Path: blob/master/test/langtools/tools/javap/T4459541.java
41144 views
/*1* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 445954126* @summary "javap -l" shows line numbers as signed short; they should be unsigned.27* @modules jdk.jdeps/com.sun.tools.javap28*/2930import java.io.*;3132public class T4459541 {33public static void main(String[] args) throws Exception {34new T4459541().run();35}3637public void run() throws IOException {38File javaFile = writeTestFile();39File classFile = compileTestFile(javaFile);40String output = javap(classFile);41verify(output);42}4344File writeTestFile() throws IOException {45File f = new File("Test.java");46out = new PrintWriter(new BufferedWriter(new FileWriter(f)));47println("class Test {");48println("void begin(int i) {");49println("i++;");50println("i++;");51println("}");52while (line < 32750)53println("// " + line);54println("void before_32767(int i) {");55println("i++;");56println("i++;");57println("}");58while (line < 32768-4)59println("// " + line);60println("void straddle_32768(int i) {");61while (line < 32768+4)62println("i++;");63println("}");64while (line < 65520)65println("// " + line);66println("void between_32768_and_65536(int i) {");67println("i++;");68println("i++;");69println("}");70while (line < 65536-4)71println("// " + line);72println("void straddle_65536(int i) {");73while (line < 65536+4)74println("i++;");75println("}");76println("}");77out.close();78return f;79}8081File compileTestFile(File f) {82int rc = com.sun.tools.javac.Main.compile(new String[] { f.getPath() });83if (rc != 0)84throw new Error("compilation failed. rc=" + rc);85String path = f.getPath();86return new File(path.substring(0, path.length() - 5) + ".class");87}8889String javap(File f) {90StringWriter sw = new StringWriter();91PrintWriter out = new PrintWriter(sw);92int rc = com.sun.tools.javap.Main.run(new String[] { "-l", f.getPath() }, out);93if (rc != 0)94throw new Error("javap failed. rc=" + rc);95out.close();96return sw.toString();97}9899void verify(String output) {100System.out.println(output);101if (output.indexOf("-") >= 0)102throw new Error("- found in output");103}104105void println(String text) {106out.println(text);107line++;108}109110PrintWriter out;111int line = 1;112}113114115