author | alanb |
Thu, 01 Dec 2016 15:54:39 +0000 | |
changeset 42309 | 21f9f3fbc302 |
parent 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
25470
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36851
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
25470
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
4 |
* |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
8 |
* |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
13 |
* accompanied this code). |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
14 |
* |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
18 |
* |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
21 |
* questions. |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
22 |
*/ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
23 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
24 |
import java.io.File; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
25 |
import java.io.FileOutputStream; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
26 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
27 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
28 |
import static jdk.internal.org.objectweb.asm.Opcodes.*; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36851
diff
changeset
|
29 |
import jdk.test.lib.process.ProcessTools; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36851
diff
changeset
|
30 |
import jdk.test.lib.process.OutputAnalyzer; |
25470
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
31 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
32 |
/* |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
33 |
* @test OverriderMsg |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
34 |
* @bug 8026894 |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36851
diff
changeset
|
35 |
* @library /test/lib |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
25470
diff
changeset
|
36 |
* @modules java.base/jdk.internal.org.objectweb.asm |
36851 | 37 |
* java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
25470
diff
changeset
|
38 |
* java.management |
25470
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
39 |
* @compile -XDignore.symbol.file OverriderMsg.java |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
40 |
* @run main/othervm OverriderMsg |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
41 |
*/ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
42 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
43 |
// This test checks that the super class name is included in the message when |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
44 |
// a method is detected overriding a final method in its super class. The |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
45 |
// asm part of the test creates these two classes: |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
46 |
// |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
47 |
// public class HasFinal { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
48 |
// public final void m(String s) { } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
49 |
// } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
50 |
// |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
51 |
// public class Overrider extends HasFinal { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
52 |
// public void m(String s) { } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
53 |
// public static void main(String[] args) { } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
54 |
// } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
55 |
// |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
56 |
public class OverriderMsg { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
57 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
58 |
public static void dump_HasFinal () throws Exception { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
59 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
60 |
ClassWriter cw = new ClassWriter(0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
61 |
MethodVisitor mv; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
62 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
63 |
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "HasFinal", null, "java/lang/Object", null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
64 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
65 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
66 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
67 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
68 |
mv.visitVarInsn(ALOAD, 0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
69 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
70 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
71 |
mv.visitMaxs(1, 1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
72 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
73 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
74 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
75 |
mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "m", "(Ljava/lang/String;)V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
76 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
77 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
78 |
mv.visitMaxs(0, 2); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
79 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
80 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
81 |
cw.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
82 |
try (FileOutputStream fos = new FileOutputStream(new File("HasFinal.class"))) { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
83 |
fos.write(cw.toByteArray()); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
84 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
85 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
86 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
87 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
88 |
public static void dump_Overrider () throws Exception { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
89 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
90 |
ClassWriter cw = new ClassWriter(0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
91 |
MethodVisitor mv; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
92 |
cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, "Overrider", null, "HasFinal", null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
93 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
94 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
95 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
96 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
97 |
mv.visitVarInsn(ALOAD, 0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
98 |
mv.visitMethodInsn(INVOKESPECIAL, "HasFinal", "<init>", "()V"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
99 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
100 |
mv.visitMaxs(1, 1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
101 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
102 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
103 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
104 |
mv = cw.visitMethod(ACC_PUBLIC, "m", "(Ljava/lang/String;)V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
105 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
106 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
107 |
mv.visitMaxs(0, 2); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
108 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
109 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
110 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
111 |
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
112 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
113 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
114 |
mv.visitMaxs(0, 1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
115 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
116 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
117 |
cw.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
118 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
119 |
try (FileOutputStream fos = new FileOutputStream(new File("Overrider.class"))) { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
120 |
fos.write(cw.toByteArray()); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
121 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
122 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
123 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
124 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
125 |
public static void main(String... args) throws Exception { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
126 |
dump_HasFinal(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
127 |
dump_Overrider(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
128 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-cp", ".", "Overrider"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
129 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
130 |
output.shouldContain( |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
131 |
"java.lang.VerifyError: class Overrider overrides final method HasFinal.m(Ljava/lang/String;)V"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
132 |
output.shouldHaveExitValue(1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
133 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
134 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
135 |
} |