Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/8006334/JavapTaskCtorFailWithNPE.java
32285 views
1
/*
2
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8006334
27
* @summary javap: JavapTask constructor breaks with null pointer exception if
28
* parameter options is null
29
*/
30
31
import java.io.File;
32
import java.util.Arrays;
33
import java.io.PrintWriter;
34
import java.io.StringWriter;
35
import java.util.List;
36
import java.util.Locale;
37
import javax.tools.Diagnostic;
38
import javax.tools.DiagnosticCollector;
39
import javax.tools.JavaFileManager;
40
import javax.tools.JavaFileObject;
41
import com.sun.tools.javap.JavapFileManager;
42
import com.sun.tools.javap.JavapTask;
43
44
public class JavapTaskCtorFailWithNPE {
45
46
//we will also check the output just to confirm that we get the expected one
47
private static final String expOutput =
48
"Compiled from \"JavapTaskCtorFailWithNPE.java\"\n" +
49
"public class JavapTaskCtorFailWithNPE {\n" +
50
" public JavapTaskCtorFailWithNPE();\n" +
51
" public static void main(java.lang.String[]);\n" +
52
"}\n";
53
54
public static void main(String[] args) {
55
new JavapTaskCtorFailWithNPE().run();
56
}
57
58
private void run() {
59
File classToCheck = new File(System.getProperty("test.classes"),
60
getClass().getSimpleName() + ".class");
61
62
DiagnosticCollector<JavaFileObject> dc =
63
new DiagnosticCollector<JavaFileObject>();
64
StringWriter sw = new StringWriter();
65
PrintWriter pw = new PrintWriter(sw);
66
JavaFileManager fm = JavapFileManager.create(dc, pw);
67
JavapTask t = new JavapTask(pw, fm, dc, null,
68
Arrays.asList(classToCheck.getPath()));
69
if (t.run() != 0)
70
throw new Error("javap failed unexpectedly");
71
72
List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
73
for (Diagnostic<? extends JavaFileObject> d: diags) {
74
if (d.getKind() == Diagnostic.Kind.ERROR)
75
throw new AssertionError(d.getMessage(Locale.ENGLISH));
76
}
77
String lineSep = System.getProperty("line.separator");
78
String out = sw.toString().replace(lineSep, "\n");
79
if (!out.equals(expOutput)) {
80
throw new AssertionError("The output is not equal to the one expected");
81
}
82
}
83
84
}
85
86