author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 7625 | f7374a9d9cc9 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
7625
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
1 |
/* |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
4 |
* |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
8 |
* |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
14 |
* |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
18 |
* |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
21 |
* questions. |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
22 |
*/ |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
23 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
24 |
/* |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
25 |
* @test |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
26 |
* @bug 7004698 |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
27 |
* @summary javap does not output CharacterRangeTable attributes correctly |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
28 |
*/ |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
29 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
30 |
import java.io.*; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
31 |
import java.util.*; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
32 |
import java.util.regex.*; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
33 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
34 |
public class T7004698 { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
35 |
public static void main(String... args) throws Exception { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
36 |
new T7004698().run(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
37 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
38 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
39 |
void run() throws Exception { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
40 |
File srcDir = new File(System.getProperty("test.src")); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
41 |
File srcFile = new File(srcDir, T7004698.class.getSimpleName() + ".java"); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
42 |
File classesDir = new File("."); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
43 |
compile("-Xjcov", "-d", classesDir.getPath(), srcFile.getPath()); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
44 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
45 |
File classFile = new File(classesDir, T7004698.class.getSimpleName() + ".class"); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
46 |
String out = javap("-v", classFile.getPath()); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
47 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
48 |
Pattern attrBody = Pattern.compile("[0-9a-f, ]+//[-0-9a-z:, ]+"); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
49 |
Pattern endOfAttr = Pattern.compile("(^$|[A-Z][A-Za-z0-9_]+:.*|})"); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
50 |
boolean inAttr = false; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
51 |
int count = 0; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
52 |
int errors = 0; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
53 |
for (String line: out.split(System.getProperty("line.separator"))) { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
54 |
line = line.trim(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
55 |
if (line.equals("CharacterRangeTable:")) { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
56 |
inAttr = true; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
57 |
count++; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
58 |
} else if (inAttr) { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
59 |
if (endOfAttr.matcher(line).matches()) { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
60 |
inAttr = false; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
61 |
} else if (!attrBody.matcher(line).matches()) { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
62 |
System.err.println("unexpected line found: " + line); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
63 |
errors++; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
64 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
65 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
66 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
67 |
if (count == 0) |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
68 |
throw new Exception("no attribute instances found"); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
69 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
70 |
if (errors > 0) |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
71 |
throw new Exception(errors + " errors found"); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
72 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
73 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
74 |
void compile(String... args) throws Exception { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
75 |
StringWriter sw = new StringWriter(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
76 |
PrintWriter pw = new PrintWriter(sw); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
77 |
int rc = com.sun.tools.javac.Main.compile(args, pw); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
78 |
pw.close(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
79 |
String out = sw.toString(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
80 |
if (!out.isEmpty()) |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
81 |
System.err.println(out); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
82 |
if (rc != 0) |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
83 |
throw new Exception("javac failed unexpectedly; rc=" + rc); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
84 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
85 |
|
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
86 |
String javap(String... args) throws Exception { |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
87 |
StringWriter sw = new StringWriter(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
88 |
PrintWriter pw = new PrintWriter(sw); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
89 |
int rc = com.sun.tools.javap.Main.run(args, pw); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
90 |
pw.close(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
91 |
String out = sw.toString(); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
92 |
if (!out.isEmpty()) |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
93 |
System.err.println(out); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
94 |
if (rc != 0) |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
95 |
throw new Exception("javap failed unexpectedly; rc=" + rc); |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
96 |
return out; |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
97 |
} |
f7374a9d9cc9
7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff
changeset
|
98 |
} |