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