langtools/test/tools/javac/generics/inference/8058199/T8058199.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 27124 5b69a74c224e
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27124
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     1
/*
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     4
 *
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 27124
diff changeset
     7
 * published by the Free Software Foundation.
27124
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     8
 *
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    14
 *
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    18
 *
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    21
 * questions.
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    22
 */
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    23
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    24
/**
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    25
 * @test
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    26
 * @bug 8058199
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    27
 * @summary Code generation problem with javac skipping a checkcast instruction
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    28
 */
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    29
public class T8058199 {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    30
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    31
    final static String SYNTHETIC_CAST_TYPE = "[Ljava.lang.String;";
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    32
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    33
    @SuppressWarnings("unchecked")
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    34
    <Z> Z[] makeArr(Z z) { return (Z[])new Object[1]; }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    35
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    36
    <U> void check(U u) { }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    37
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    38
    void testMethod() {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    39
        test(() -> check(makeArr("")));
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    40
    }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    41
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    42
    void testNewDiamond() {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    43
        class Check<X> {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    44
            Check(X x) { }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    45
        }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    46
        test(()-> new Check<>(makeArr("")));
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    47
    }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    48
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    49
    void testNewGeneric() {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    50
        class Check {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    51
            <Z> Check(Z z) { }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    52
        }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    53
        test(()-> new Check(makeArr("")));
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    54
    }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    55
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    56
    private void test(Runnable r) {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    57
        try {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    58
            r.run();
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    59
            throw new AssertionError("Missing synthetic cast");
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    60
        } catch (ClassCastException cce) {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    61
            if (!cce.getMessage().contains(SYNTHETIC_CAST_TYPE)) {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    62
                throw new AssertionError("Bad type in synthetic cast", cce);
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    63
            }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    64
        }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    65
    }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    66
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    67
    public static void main(String[] args) {
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    68
        T8058199 test = new T8058199();
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    69
        test.testMethod();
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    70
        test.testNewDiamond();
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    71
        test.testNewGeneric();
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    72
    }
5b69a74c224e 8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
diff changeset
    73
}