author | hseigel |
Thu, 02 Apr 2015 08:50:10 -0400 | |
changeset 30136 | 1c5202fa105b |
parent 25470 | 4e69740b1547 |
child 29678 | dd2f3932c21e |
permissions | -rw-r--r-- |
25470
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
1 |
/* |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
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.*; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
29 |
import com.oracle.java.testlibrary.*; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
30 |
|
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 |
* @test OverriderMsg |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
33 |
* @bug 8026894 |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
34 |
* @library /testlibrary |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
35 |
* @compile -XDignore.symbol.file OverriderMsg.java |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
36 |
* @run main/othervm OverriderMsg |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
37 |
*/ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
38 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
39 |
// 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
|
40 |
// 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
|
41 |
// asm part of the test creates these two classes: |
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 |
// public class HasFinal { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
44 |
// public final void m(String s) { } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
45 |
// } |
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 Overrider extends HasFinal { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
48 |
// public void m(String s) { } |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
49 |
// public static void main(String[] args) { } |
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 |
// |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
52 |
public class OverriderMsg { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
53 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
54 |
public static void dump_HasFinal () throws Exception { |
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 |
ClassWriter cw = new ClassWriter(0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
57 |
MethodVisitor mv; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
58 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
59 |
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
|
60 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
61 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
62 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
63 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
64 |
mv.visitVarInsn(ALOAD, 0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
65 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
66 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
67 |
mv.visitMaxs(1, 1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
68 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
69 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
70 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
71 |
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
|
72 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
73 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
74 |
mv.visitMaxs(0, 2); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
75 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
76 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
77 |
cw.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
78 |
try (FileOutputStream fos = new FileOutputStream(new File("HasFinal.class"))) { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
79 |
fos.write(cw.toByteArray()); |
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 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
82 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
83 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
84 |
public static void dump_Overrider () throws Exception { |
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 |
ClassWriter cw = new ClassWriter(0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
87 |
MethodVisitor mv; |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
88 |
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
|
89 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
90 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
91 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
92 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
93 |
mv.visitVarInsn(ALOAD, 0); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
94 |
mv.visitMethodInsn(INVOKESPECIAL, "HasFinal", "<init>", "()V"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
95 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
96 |
mv.visitMaxs(1, 1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
97 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
98 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
99 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
100 |
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
|
101 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
102 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
103 |
mv.visitMaxs(0, 2); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
104 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
105 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
106 |
{ |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
107 |
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
|
108 |
mv.visitCode(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
109 |
mv.visitInsn(RETURN); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
110 |
mv.visitMaxs(0, 1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
111 |
mv.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
112 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
113 |
cw.visitEnd(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
114 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
115 |
try (FileOutputStream fos = new FileOutputStream(new File("Overrider.class"))) { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
116 |
fos.write(cw.toByteArray()); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
117 |
} |
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 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
120 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
121 |
public static void main(String... args) throws Exception { |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
122 |
dump_HasFinal(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
123 |
dump_Overrider(); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
124 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-cp", ".", "Overrider"); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
125 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
126 |
output.shouldContain( |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
127 |
"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
|
128 |
output.shouldHaveExitValue(1); |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
129 |
} |
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
130 |
|
4e69740b1547
8026894: Improve VerifyError message about overriding a final method
hseigel
parents:
diff
changeset
|
131 |
} |