test/langtools/tools/javac/conditional/T8016702.java
author darcy
Fri, 02 Feb 2018 10:29:25 -0800
changeset 48723 6cb86bf0b51e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196623: Update JavaBaseTest.java to be version agnostic Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18903
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     1
/*
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     4
 *
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     8
 *
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    14
 *
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    18
 *
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    21
 * questions.
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    22
 */
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    23
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    24
/*
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    25
 * @test
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    26
 * @bug 8016702
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    27
 * @summary use of ternary operator in lambda expression gives incorrect results
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    28
 */
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    29
import java.util.Arrays;
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    30
import java.util.List;
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    31
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    32
public class T8016702 {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    33
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    34
    static int assertionCount;
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    35
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    36
    static void assertTrue(boolean b, String msg) {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    37
        assertionCount++;
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    38
        if (!b) {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    39
            throw new AssertionError(msg);
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    40
        }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    41
    }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    42
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    43
    interface IntFunction<Y> {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    44
        Y m(int x);
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    45
    }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    46
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    47
    void test(List<Integer> li) {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    48
        map(i -> (i % 2 == 0) ? "" : "i="+i, li);
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    49
    }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    50
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    51
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    52
    @SuppressWarnings("unchecked")
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    53
    <R> void map(IntFunction<R> mapper, List<Integer> li) {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    54
        for (int i : li) {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    55
            String res = (String)mapper.m(i);
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    56
            assertTrue((i % 2 == 0) ? res.isEmpty() : res.contains("" + i),
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    57
                    "i = " + i + " res = " + res);
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    58
        }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    59
    }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    60
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    61
    public static void main(String[] args) {
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    62
        T8016702 tester = new T8016702();
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    63
        tester.test(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    64
        assertTrue(assertionCount == 10, "wrong assertion count: " + assertionCount);
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    65
    }
99f42bd11bc2 8016702: use of ternary operator in lambda expression gives incorrect results
mcimadamore
parents:
diff changeset
    66
}