T4880663.java revision 952
405N/A/*
405N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
405N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
405N/A *
405N/A * This code is free software; you can redistribute it and/or modify it
405N/A * under the terms of the GNU General Public License version 2 only, as
405N/A * published by the Free Software Foundation.
405N/A *
405N/A * This code is distributed in the hope that it will be useful, but WITHOUT
405N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
405N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
405N/A * version 2 for more details (a copy is included in the LICENSE file that
405N/A * accompanied this code).
405N/A *
405N/A * You should have received a copy of the GNU General Public License version
405N/A * 2 along with this work; if not, write to the Free Software Foundation,
405N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
405N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
405N/A */
405N/A
405N/A/*
405N/A * @test
405N/A * @bug 4880663 6715757 7031005
405N/A * @summary javap could output whitespace between class name and opening brace
405N/A * javap prints "extends java.lang.Object"
405N/A */
405N/A
405N/A
405N/Aimport java.io.*;
405N/A
405N/Apublic class T4880663 {
405N/A public static void main(String[] args) throws Exception {
405N/A new T4880663().run();
405N/A }
405N/A
405N/A public void run() throws IOException {
405N/A File javaFile = writeTestFile();
405N/A File classFile = compileTestFile(javaFile);
405N/A verify(classFile, "class Test {");
405N/A
405N/A if (errors > 0)
405N/A throw new Error(errors + " found.");
405N/A }
405N/A
405N/A File writeTestFile() throws IOException {
405N/A File f = new File("Test.java");
405N/A PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
405N/A out.println("class Test { }");
405N/A out.close();
return f;
}
File compileTestFile(File f) {
int rc = com.sun.tools.javac.Main.compile(new String[] { "-g", f.getPath() });
if (rc != 0)
throw new Error("compilation failed. rc=" + rc);
String path = f.getPath();
return new File(path.substring(0, path.length() - 5) + ".class");
}
String javap(File classFile) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
int rc = com.sun.tools.javap.Main.run(new String[] { classFile.getPath() }, out);
if (rc != 0)
throw new Error("javap failed. rc=" + rc);
out.close();
System.out.println(sw.toString());
return sw.toString();
}
void verify(File classFile, String... expects) {
String output = javap(classFile);
for (String expect: expects) {
if (output.indexOf(expect)< 0)
error(expect + " not found");
}
}
void error(String msg) {
System.err.println(msg);
errors++;
}
int errors;
}