Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T8032814.java
32285 views
/*1* Copyright (c) 2014, 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 803281426* @summary LineNumberTable/LocalVariableTable tables duplication for the27* "-v -l" combination of options28* @compile -g T8032814.java29* @run main T803281430*/3132import java.io.*;33import java.util.*;3435public class T8032814 {36public static void main(String... args) throws Exception {37new T8032814().run();38}3940void run() throws Exception {41Class<?> clazz = T8032814.class;42int count = clazz.getDeclaredConstructors().length43+ clazz.getDeclaredMethods().length;44test(clazz, 0);45test(clazz, count, "-v");46test(clazz, count, "-l");47test(clazz, count, "-v", "-l");4849if (errors > 0)50throw new Exception(errors + " errors occurred");51}5253void test(Class<?> clazz, int expectedCount, String... opts) throws Exception {54System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount);55List<String> args = new ArrayList<String>();56args.addAll(Arrays.asList(opts));57args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));58args.add(clazz.getName());59StringWriter sw = new StringWriter();60PrintWriter pw = new PrintWriter(sw);61int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);62pw.close();63String out = sw.toString();64if (rc != 0)65throw new Exception("javap failed unexpectedly: rc=" + rc);6667int lntCount = 0, lvtCount = 0;68for (String line: out.split("[\r\n]+")) {69if (line.matches("^ *LineNumberTable:$"))70lntCount++;71if (line.matches("^ *LocalVariableTable:$"))72lvtCount++;73}74checkEqual("LineNumberTable", lntCount, expectedCount);75checkEqual("LocalVariableTable", lvtCount, expectedCount);76}7778void checkEqual(String attr, int found, int expect) {79if (found != expect) {80error("Unexpected number of occurrences of " + attr + "\n" +81"found: " + found + ", expected: " + expect);82}83}8485void error(String msg) {86System.err.println("Error: " + msg);87errors++;88}8990int errors = 0;91}92939495