Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/4111861/T4111861.java
32285 views
1
/*
2
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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.
8
*
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).
14
*
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.
18
*
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
21
* questions.
22
*/
23
24
import java.io.*;
25
26
/*
27
* @test
28
* @bug 4111861
29
* @summary static final field contents are not displayed
30
*/
31
public class T4111861 {
32
public static void main(String... args) throws Exception {
33
new T4111861().run();
34
}
35
36
void run() throws Exception {
37
File testSrc = new File(System.getProperty("test.src", "."));
38
File a_java = new File(testSrc, "A.java");
39
javac("-d", ".", a_java.getPath());
40
41
String out = javap("-classpath", ".", "-constants", "A");
42
43
String a = read(a_java);
44
45
if (!filter(out).equals(filter(read(a_java)))) {
46
System.out.println(out);
47
throw new Exception("unexpected output");
48
}
49
}
50
51
String javac(String... args) throws Exception {
52
StringWriter sw = new StringWriter();
53
PrintWriter pw = new PrintWriter(sw);
54
int rc = com.sun.tools.javac.Main.compile(args, pw);
55
if (rc != 0)
56
throw new Exception("javac failed, rc=" + rc);
57
return sw.toString();
58
}
59
60
String javap(String... args) throws Exception {
61
StringWriter sw = new StringWriter();
62
PrintWriter pw = new PrintWriter(sw);
63
int rc = com.sun.tools.javap.Main.run(args, pw);
64
if (rc != 0)
65
throw new Exception("javap failed, rc=" + rc);
66
return sw.toString();
67
}
68
69
String read(File f) throws IOException {
70
StringBuilder sb = new StringBuilder();
71
BufferedReader in = new BufferedReader(new FileReader(f));
72
try {
73
String line;
74
while ((line = in.readLine()) != null) {
75
sb.append(line);
76
sb.append('\n');
77
}
78
} finally {
79
in.close();
80
}
81
return sb.toString();
82
}
83
84
// return those lines beginning "public static final"
85
String filter(String s) throws IOException {
86
StringBuilder sb = new StringBuilder();
87
BufferedReader in = new BufferedReader(new StringReader(s));
88
try {
89
String line;
90
while ((line = in.readLine()) != null) {
91
if (line.indexOf("public static final") > 0) {
92
sb.append(line.trim());
93
sb.append('\n');
94
}
95
}
96
} finally {
97
in.close();
98
}
99
return sb.toString();
100
}
101
}
102
103