Thu, 21 Feb 2013 15:26:46 +0000
8007461: Regression: bad overload resolution when inner class and outer class have method with same name
Summary: Fix regression in varargs method resolution introduced by bad refactoring
Reviewed-by: jjg
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 */
24 /*
25 * @test
26 * @bug 8006334
27 * @summary javap: JavapTask constructor breaks with null pointer exception if
28 * parameter options is null
29 */
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;
44 public class JavapTaskCtorFailWithNPE {
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";
54 public static void main(String[] args) {
55 new JavapTaskCtorFailWithNPE().run();
56 }
58 private void run() {
59 File classToCheck = new File(System.getProperty("test.classes"),
60 getClass().getSimpleName() + ".class");
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 boolean ok = t.run();
70 if (!ok)
71 throw new Error("javap failed unexpectedly");
73 List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
74 for (Diagnostic<? extends JavaFileObject> d: diags) {
75 if (d.getKind() == Diagnostic.Kind.ERROR)
76 throw new AssertionError(d.getMessage(Locale.ENGLISH));
77 }
78 String lineSep = System.getProperty("line.separator");
79 String out = sw.toString().replace(lineSep, "\n");
80 if (!out.equals(expOutput)) {
81 throw new AssertionError("The output is not equal to the one expected");
82 }
83 }
85 }