langtools/test/tools/javap/8006334/JavapTaskCtorFailWithNPE.java
author enevill
Tue, 05 May 2015 09:08:20 +0000
changeset 30325 1472b22475f2
parent 18388 7d67f9206d8f
child 30730 d3ce7619db2c
permissions -rw-r--r--
8078245: AARCH64: JDK fails to build due to undefined symbol in libpng Summary: Add -DPNG_ARM_NEON_OPT=0 to LIBSPLASHSCREEN_CFLAGS flags Reviewed-by: dholmes, ihse, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15716
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     1
/*
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     4
 *
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     8
 *
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    13
 * accompanied this code).
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    14
 *
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    18
 *
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    21
 * questions.
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    22
 */
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    23
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    24
/*
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    25
 * @test
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    26
 * @bug 8006334
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    27
 * @summary javap: JavapTask constructor breaks with null pointer exception if
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    28
 * parameter options is null
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    29
 */
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    30
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    31
import java.io.File;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    32
import java.util.Arrays;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    33
import java.io.PrintWriter;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    34
import java.io.StringWriter;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    35
import java.util.List;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    36
import java.util.Locale;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    37
import javax.tools.Diagnostic;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    38
import javax.tools.DiagnosticCollector;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    39
import javax.tools.JavaFileManager;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    40
import javax.tools.JavaFileObject;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    41
import com.sun.tools.javap.JavapFileManager;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    42
import com.sun.tools.javap.JavapTask;
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    43
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    44
public class JavapTaskCtorFailWithNPE {
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    45
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    46
    //we will also check the output just to confirm that we get the expected one
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    47
    private static final String expOutput =
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    48
        "Compiled from \"JavapTaskCtorFailWithNPE.java\"\n" +
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    49
        "public class JavapTaskCtorFailWithNPE {\n" +
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    50
        "  public JavapTaskCtorFailWithNPE();\n" +
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    51
        "  public static void main(java.lang.String[]);\n" +
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    52
        "}\n";
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    53
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    54
    public static void main(String[] args) {
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    55
        new JavapTaskCtorFailWithNPE().run();
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    56
    }
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    57
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    58
    private void run() {
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    59
        File classToCheck = new File(System.getProperty("test.classes"),
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    60
            getClass().getSimpleName() + ".class");
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    61
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    62
        DiagnosticCollector<JavaFileObject> dc =
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    63
                new DiagnosticCollector<JavaFileObject>();
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    64
        StringWriter sw = new StringWriter();
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    65
        PrintWriter pw = new PrintWriter(sw);
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    66
        JavaFileManager fm = JavapFileManager.create(dc, pw);
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    67
        JavapTask t = new JavapTask(pw, fm, dc, null,
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    68
                Arrays.asList(classToCheck.getPath()));
18388
7d67f9206d8f 8007907: javap, method com.sun.tools.javap.Main.run returns 0 even in case of class not found error
vromero
parents: 15716
diff changeset
    69
        if (t.run() != 0)
15716
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    70
            throw new Error("javap failed unexpectedly");
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    71
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    72
        List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    73
        for (Diagnostic<? extends JavaFileObject> d: diags) {
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    74
            if (d.getKind() == Diagnostic.Kind.ERROR)
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    75
                throw new AssertionError(d.getMessage(Locale.ENGLISH));
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    76
        }
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    77
        String lineSep = System.getProperty("line.separator");
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    78
        String out = sw.toString().replace(lineSep, "\n");
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    79
        if (!out.equals(expOutput)) {
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    80
            throw new AssertionError("The output is not equal to the one expected");
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    81
        }
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    82
    }
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    83
d1f59adb0d83 8006334: javap, JavapTask constructor breaks with null pointer exception if parameter options is null
vromero
parents:
diff changeset
    84
}