Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/pack200/AttributeTests.java
38833 views
1
/*
2
* Copyright (c) 2010, 2013, 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
import java.io.File;
24
import java.util.ArrayList;
25
import java.util.Arrays;
26
import java.util.List;
27
/*
28
* @test
29
* @bug 6746111 8005252 8008262
30
* @summary tests various classfile format and attribute handling by pack200
31
* @compile -XDignore.symbol.file Utils.java AttributeTests.java
32
* @run main AttributeTests
33
* @author ksrini
34
*/
35
public class AttributeTests {
36
37
public static void main(String... args) throws Exception {
38
test6746111();
39
testMethodParameters();
40
Utils.cleanup();
41
}
42
43
/*
44
* this tests ensure that MethodParameters produces by javac is packed
45
* correctly. Usually this is not the case as new attributes are available
46
* in the sdk jars, since MethodParameters happens to be an optional
47
* attribute, thus this test.
48
*/
49
static void testMethodParameters() throws Exception {
50
List<String> scratch = new ArrayList<>();
51
final String fname = "MP";
52
String javaFileName = fname + Utils.JAVA_FILE_EXT;
53
String javaClassName = fname + Utils.CLASS_FILE_EXT;
54
scratch.add("class " + fname + " {");
55
scratch.add("void foo2(int j, final int k){}");
56
scratch.add("}");
57
File cwd = new File(".");
58
File javaFile = new File(cwd, javaFileName);
59
Utils.createFile(javaFile, scratch);
60
61
Utils.compiler(javaFile.getName(), "-parameters");
62
63
// jar the file up
64
File testjarFile = new File(cwd, "test" + Utils.JAR_FILE_EXT);
65
Utils.jar("cvf", testjarFile.getName(), javaClassName);
66
67
Utils.testWithRepack(testjarFile, "--unknown-attribute=error");
68
}
69
/*
70
* this test checks to see if we get the expected strings for output
71
*/
72
static void test6746111() throws Exception {
73
String pack200Cmd = Utils.getPack200Cmd();
74
File badAttrJar = new File(".", "badattr.jar");
75
Utils.copyFile(new File(Utils.TEST_SRC_DIR, "badattr.jar"), badAttrJar);
76
File testJar = new File(".", "test.jar");
77
List<String> cmds = new ArrayList<String>();
78
cmds.add(pack200Cmd);
79
cmds.add("--repack");
80
cmds.add("-v");
81
cmds.add(testJar.getAbsolutePath());
82
cmds.add(badAttrJar.getAbsolutePath());
83
List<String> output = Utils.runExec(cmds);
84
/*
85
* compare the repacked jar bit-wise, as all the files
86
* should be transmitted "as-is".
87
*/
88
Utils.doCompareBitWise(badAttrJar.getAbsoluteFile(), testJar.getAbsoluteFile());
89
String[] expectedStrings = {
90
"WARNING: Passing class file uncompressed due to unrecognized" +
91
" attribute: Foo.class",
92
"INFO: com.sun.java.util.jar.pack.Attribute$FormatException: " +
93
"class attribute \"XourceFile\": is unknown attribute " +
94
"in class Foo",
95
"INFO: com.sun.java.util.jar.pack.ClassReader$ClassFormatException: " +
96
"AnnotationDefault: attribute length cannot be zero, in Test.message()",
97
"WARNING: Passing class file uncompressed due to unknown class format: Test.class"
98
};
99
List<String> notfoundList = new ArrayList<String>();
100
notfoundList.addAll(Arrays.asList(expectedStrings));
101
// make sure the expected messages are emitted
102
for (String x : output) {
103
findString(x, notfoundList, expectedStrings);
104
}
105
if (!notfoundList.isEmpty()) {
106
System.out.println("Not found:");
107
for (String x : notfoundList) {
108
System.out.println(x);
109
}
110
throw new Exception("Test fails: " + notfoundList.size() +
111
" expected strings not found");
112
}
113
testJar.delete();
114
badAttrJar.delete();
115
}
116
117
private static void findString(String outputStr, List<String> notfoundList,
118
String[] expectedStrings) {
119
for (String y : expectedStrings) {
120
if (outputStr.contains(y)) {
121
notfoundList.remove(y);
122
return;
123
}
124
}
125
}
126
}
127
128