2
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
27
* @summary LineNumberTable/LocalVariableTable tables duplication for the
28
* "-v -l" combination of options
29
* @modules jdk.jdeps/com.sun.tools.javap
30
* @compile -g T8032814.java
37
public class T8032814 {
38
public static void main(String... args) throws Exception {
42
void run() throws Exception {
43
Class<?> clazz = T8032814.class;
44
int count = clazz.getDeclaredConstructors().length
45
+ clazz.getDeclaredMethods().length;
47
test(clazz, count, "-v");
48
test(clazz, count, "-l");
49
test(clazz, count, "-v", "-l");
52
throw new Exception(errors + " errors occurred");
55
void test(Class<?> clazz, int expectedCount, String... opts) throws Exception {
56
System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount);
57
List<String> args = new ArrayList<String>();
58
args.addAll(Arrays.asList(opts));
59
args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));
60
args.add(clazz.getName());
61
StringWriter sw = new StringWriter();
62
PrintWriter pw = new PrintWriter(sw);
63
int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
65
String out = sw.toString();
67
throw new Exception("javap failed unexpectedly: rc=" + rc);
69
int lntCount = 0, lvtCount = 0;
70
for (String line: out.split("[\r\n]+")) {
71
if (line.matches("^ *LineNumberTable:$"))
73
if (line.matches("^ *LocalVariableTable:$"))
76
checkEqual("LineNumberTable", lntCount, expectedCount);
77
checkEqual("LocalVariableTable", lvtCount, expectedCount);
80
void checkEqual(String attr, int found, int expect) {
81
if (found != expect) {
82
error("Unexpected number of occurrences of " + attr + "\n" +
83
"found: " + found + ", expected: " + expect);
87
void error(String msg) {
88
System.err.println("Error: " + msg);