author | stefank |
Wed, 20 Apr 2016 09:58:15 +0200 | |
changeset 38000 | 7519aefb5b86 |
parent 36851 | 03e2f4d0a421 |
child 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
22752 | 1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
22752
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
22752 | 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 |
/* |
|
25 |
* @test |
|
26 |
* @library /testlibrary |
|
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
22752
diff
changeset
|
27 |
* @modules java.base/jdk.internal.org.objectweb.asm |
36851 | 28 |
* java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
22752
diff
changeset
|
29 |
* java.management |
22752 | 30 |
* @compile -XDignore.symbol.file UnsupportedClassFileVersion.java |
31 |
* @run main UnsupportedClassFileVersion |
|
32 |
*/ |
|
33 |
||
34 |
import java.io.File; |
|
35 |
import java.io.FileOutputStream; |
|
36 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
|
37 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
|
38 |
import jdk.internal.org.objectweb.asm.Opcodes; |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
39 |
import jdk.test.lib.*; |
22752 | 40 |
|
41 |
public class UnsupportedClassFileVersion implements Opcodes { |
|
42 |
public static void main(String... args) throws Exception { |
|
43 |
writeClassFile(); |
|
44 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-cp", ".", "ClassFile"); |
|
45 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
46 |
output.shouldContain("ClassFile has been compiled by a more recent version of the " + |
|
47 |
"Java Runtime (class file version 99.0), this version of " + |
|
48 |
"the Java Runtime only recognizes class file versions up to " + |
|
49 |
System.getProperty("java.class.version")); |
|
50 |
||
51 |
output.shouldHaveExitValue(1); |
|
52 |
} |
|
53 |
||
54 |
public static void writeClassFile() throws Exception { |
|
55 |
ClassWriter cw = new ClassWriter(0); |
|
56 |
MethodVisitor mv; |
|
57 |
||
58 |
cw.visit(99, ACC_PUBLIC + ACC_SUPER, "ClassFile", null, "java/lang/Object", null); |
|
59 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
|
60 |
mv.visitCode(); |
|
61 |
mv.visitVarInsn(ALOAD, 0); |
|
62 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); |
|
63 |
mv.visitInsn(RETURN); |
|
64 |
mv.visitMaxs(1, 1); |
|
65 |
mv.visitEnd(); |
|
66 |
cw.visitEnd(); |
|
67 |
||
68 |
try (FileOutputStream fos = new FileOutputStream(new File("ClassFile.class"))) { |
|
69 |
fos.write(cw.toByteArray()); |
|
70 |
} |
|
71 |
} |
|
72 |
} |