langtools/test/tools/javac/8074306/TestSyntheticNullChecks.java
author mcimadamore
Fri, 06 Mar 2015 10:30:44 +0000
changeset 29425 c88514c93554
parent 29295 5a367770a074
child 32337 c9d3ab9f601c
permissions -rw-r--r--
8074306: NULLCHK is emitted as Object.getClass 8074501: Javac fix for 8073432 is missing right test BugIDs Summary: Correct test bugIds Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29295
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     1
/*
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     4
 *
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    10
 *
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    15
 * accompanied this code).
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    16
 *
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    20
 *
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    23
 * questions.
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    24
 */
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    25
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    26
/*
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    27
 * @test
29425
c88514c93554 8074306: NULLCHK is emitted as Object.getClass
mcimadamore
parents: 29295
diff changeset
    28
 * @bug 8074306 8073432 8074501
29295
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    29
 * @summary NULLCHK is emitted as Object.getClass
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    30
 * @compile -source 6 -target 6 TestSyntheticNullChecks.java
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    31
 * @run main TestSyntheticNullChecks 6
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    32
 * @clean TestSyntheticNullChecks*
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    33
 * @compile -source 7 -target 7 TestSyntheticNullChecks.java
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    34
 * @run main TestSyntheticNullChecks 7
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    35
 * @clean TestSyntheticNullChecks*
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    36
 * @compile TestSyntheticNullChecks.java
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    37
 * @run main TestSyntheticNullChecks 9
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    38
 */
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    39
public class TestSyntheticNullChecks {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    40
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    41
    class Inner { }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    42
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    43
    static void generateSyntheticNPE(TestSyntheticNullChecks outer) {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    44
        outer.new Inner(); //javac will generate a synthetic NPE check for 'outer'
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    45
    }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    46
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    47
    public static void main(String[] args) {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    48
        int version = Integer.valueOf(args[0]);
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    49
        boolean useObjects = version >= 7;
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    50
        try {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    51
            generateSyntheticNPE(null);
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    52
        } catch (NullPointerException npe) {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    53
            boolean hasRequireNotNull = false;
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    54
            for (StackTraceElement e : npe.getStackTrace()) {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    55
                if (e.getClassName().equals("java.util.Objects") &&
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    56
                        e.getMethodName().equals("requireNonNull")) {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    57
                    hasRequireNotNull = true;
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    58
                    break;
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    59
                }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    60
            }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    61
            if (hasRequireNotNull != useObjects) {
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    62
                throw new AssertionError();
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    63
            }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    64
        }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    65
    }
5a367770a074 8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
diff changeset
    66
}