Mercurial > hg > graal-compiler
annotate test/runtime/RedefineTests/RedefineAnnotations.java @ 22017:66dd063eb6a0
renamed mx/ to mx.graal/ in preparation for working with mxtool2
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 17 Jun 2015 13:56:55 +0200 |
parents | 50054b63f0aa |
children |
rev | line source |
---|---|
20613
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
1 /* |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
4 * |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
8 * |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
13 * accompanied this code). |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
14 * |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
18 * |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
21 * questions. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
22 */ |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
23 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
24 /* |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
25 * @test |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
26 * @library /testlibrary |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
27 * @summary Test that type annotations are retained after a retransform |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
28 * @run main RedefineAnnotations buildagent |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
29 * @run main/othervm -javaagent:redefineagent.jar RedefineAnnotations |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
30 */ |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
31 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
32 import static com.oracle.java.testlibrary.Asserts.assertTrue; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
33 import java.io.FileNotFoundException; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
34 import java.io.PrintWriter; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
35 import java.lang.NoSuchFieldException; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
36 import java.lang.NoSuchMethodException; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
37 import java.lang.RuntimeException; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
38 import java.lang.annotation.Annotation; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
39 import java.lang.annotation.ElementType; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
40 import java.lang.annotation.Retention; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
41 import java.lang.annotation.RetentionPolicy; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
42 import java.lang.annotation.Target; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
43 import java.lang.instrument.ClassFileTransformer; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
44 import java.lang.instrument.IllegalClassFormatException; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
45 import java.lang.instrument.Instrumentation; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
46 import java.lang.instrument.UnmodifiableClassException; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
47 import java.lang.reflect.AnnotatedArrayType; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
48 import java.lang.reflect.AnnotatedParameterizedType; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
49 import java.lang.reflect.AnnotatedType; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
50 import java.lang.reflect.AnnotatedWildcardType; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
51 import java.lang.reflect.Executable; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
52 import java.lang.reflect.TypeVariable; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
53 import java.security.ProtectionDomain; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
54 import java.util.Arrays; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
55 import java.util.LinkedList; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
56 import java.util.List; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
57 import java.util.Map; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
58 import jdk.internal.org.objectweb.asm.ClassReader; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
59 import jdk.internal.org.objectweb.asm.ClassVisitor; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
60 import jdk.internal.org.objectweb.asm.ClassWriter; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
61 import jdk.internal.org.objectweb.asm.FieldVisitor; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
62 import static jdk.internal.org.objectweb.asm.Opcodes.ASM5; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
63 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
64 @Retention(RetentionPolicy.RUNTIME) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
65 @Target(ElementType.TYPE_USE) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
66 @interface TestAnn { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
67 String site(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
68 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
69 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
70 public class RedefineAnnotations { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
71 static Instrumentation inst; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
72 public static void premain(String agentArgs, Instrumentation inst) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
73 RedefineAnnotations.inst = inst; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
74 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
75 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
76 static class Transformer implements ClassFileTransformer { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
77 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
78 public byte[] asm(ClassLoader loader, String className, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
79 Class<?> classBeingRedefined, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
80 ProtectionDomain protectionDomain, byte[] classfileBuffer) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
81 throws IllegalClassFormatException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
82 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
83 ClassWriter cw = new ClassWriter(0); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
84 ClassVisitor cv = new ReAddDummyFieldsClassVisitor(ASM5, cw) { }; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
85 ClassReader cr = new ClassReader(classfileBuffer); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
86 cr.accept(cv, 0); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
87 return cw.toByteArray(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
88 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
89 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
90 public class ReAddDummyFieldsClassVisitor extends ClassVisitor { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
91 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
92 LinkedList<F> fields = new LinkedList<>(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
93 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
94 public ReAddDummyFieldsClassVisitor(int api, ClassVisitor cv) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
95 super(api, cv); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
96 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
97 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
98 @Override public FieldVisitor visitField(int access, String name, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
99 String desc, String signature, Object value) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
100 if (name.startsWith("dummy")) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
101 // Remove dummy field |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
102 fields.addLast(new F(access, name, desc, signature, value)); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
103 return null; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
104 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
105 return cv.visitField(access, name, desc, signature, value); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
106 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
107 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
108 @Override public void visitEnd() { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
109 F f; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
110 while ((f = fields.pollFirst()) != null) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
111 // Re-add dummy fields |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
112 cv.visitField(f.access, f.name, f.desc, f.signature, f.value); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
113 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
114 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
115 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
116 private class F { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
117 private int access; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
118 private String name; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
119 private String desc; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
120 private String signature; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
121 private Object value; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
122 F(int access, String name, String desc, String signature, Object value) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
123 this.access = access; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
124 this.name = name; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
125 this.desc = desc; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
126 this.signature = signature; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
127 this.value = value; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
128 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
129 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
130 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
131 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
132 @Override public byte[] transform(ClassLoader loader, String className, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
133 Class<?> classBeingRedefined, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
134 ProtectionDomain protectionDomain, byte[] classfileBuffer) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
135 throws IllegalClassFormatException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
136 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
137 if (className.contains("TypeAnnotatedTestClass")) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
138 try { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
139 // Here we remove and re-add the dummy fields. This shuffles the constant pool |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
140 return asm(loader, className, classBeingRedefined, protectionDomain, classfileBuffer); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
141 } catch (Throwable e) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
142 // The retransform native code that called this method does not propagate |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
143 // exceptions. Instead of getting an uninformative generic error, catch |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
144 // problems here and print it, then exit. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
145 e.printStackTrace(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
146 System.exit(1); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
147 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
148 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
149 return null; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
150 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
151 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
152 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
153 private static void buildAgent() { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
154 try { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
155 ClassFileInstaller.main("RedefineAnnotations"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
156 } catch (Exception e) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
157 throw new RuntimeException("Could not write agent classfile", e); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
158 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
159 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
160 try { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
161 PrintWriter pw = new PrintWriter("MANIFEST.MF"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
162 pw.println("Premain-Class: RedefineAnnotations"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
163 pw.println("Agent-Class: RedefineAnnotations"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
164 pw.println("Can-Retransform-Classes: true"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
165 pw.close(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
166 } catch (FileNotFoundException e) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
167 throw new RuntimeException("Could not write manifest file for the agent", e); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
168 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
169 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
170 sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
171 if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineAnnotations.class" })) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
172 throw new RuntimeException("Could not write the agent jar file"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
173 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
174 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
175 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
176 public static void main(String argv[]) throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
177 if (argv.length == 1 && argv[0].equals("buildagent")) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
178 buildAgent(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
179 return; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
180 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
181 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
182 if (inst == null) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
183 throw new RuntimeException("Instrumentation object was null"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
184 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
185 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
186 RedefineAnnotations test = new RedefineAnnotations(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
187 test.testTransformAndVerify(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
188 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
189 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
190 // Class type annotations |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
191 private Annotation classTypeParameterTA; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
192 private Annotation extendsTA; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
193 private Annotation implementsTA; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
194 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
195 // Field type annotations |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
196 private Annotation fieldTA; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
197 private Annotation innerTA; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
198 private Annotation[] arrayTA = new Annotation[4]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
199 private Annotation[] mapTA = new Annotation[5]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
200 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
201 // Method type annotations |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
202 private Annotation returnTA, methodTypeParameterTA, formalParameterTA, throwsTA; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
203 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
204 private void testTransformAndVerify() |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
205 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
206 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
207 Class<TypeAnnotatedTestClass> c = TypeAnnotatedTestClass.class; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
208 Class<?> myClass = c; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
209 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
210 /* |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
211 * Verify that the expected annotations are where they should be before transform. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
212 */ |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
213 verifyClassTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
214 verifyFieldTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
215 verifyMethodTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
216 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
217 try { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
218 inst.addTransformer(new Transformer(), true); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
219 inst.retransformClasses(myClass); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
220 } catch (UnmodifiableClassException e) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
221 throw new RuntimeException(e); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
222 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
223 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
224 /* |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
225 * Verify that the expected annotations are where they should be after transform. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
226 * Also verify that before and after are equal. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
227 */ |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
228 verifyClassTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
229 verifyFieldTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
230 verifyMethodTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
231 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
232 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
233 private void verifyClassTypeAnnotations(Class c) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
234 Annotation anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
235 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
236 anno = c.getTypeParameters()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
237 verifyTestAnn(classTypeParameterTA, anno, "classTypeParameter"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
238 classTypeParameterTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
239 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
240 anno = c.getAnnotatedSuperclass().getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
241 verifyTestAnn(extendsTA, anno, "extends"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
242 extendsTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
243 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
244 anno = c.getAnnotatedInterfaces()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
245 verifyTestAnn(implementsTA, anno, "implements"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
246 implementsTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
247 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
248 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
249 private void verifyFieldTypeAnnotations(Class c) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
250 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
251 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
252 verifyBasicFieldTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
253 verifyInnerFieldTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
254 verifyArrayFieldTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
255 verifyMapFieldTypeAnnotations(c); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
256 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
257 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
258 private void verifyBasicFieldTypeAnnotations(Class c) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
259 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
260 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
261 Annotation anno = c.getDeclaredField("typeAnnotatedBoolean").getAnnotatedType().getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
262 verifyTestAnn(fieldTA, anno, "field"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
263 fieldTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
264 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
265 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
266 private void verifyInnerFieldTypeAnnotations(Class c) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
267 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
268 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
269 AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
270 Annotation anno = at.getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
271 verifyTestAnn(innerTA, anno, "inner"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
272 innerTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
273 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
274 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
275 private void verifyArrayFieldTypeAnnotations(Class c) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
276 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
277 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
278 Annotation anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
279 AnnotatedType at; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
280 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
281 at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
282 anno = at.getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
283 verifyTestAnn(arrayTA[0], anno, "array1"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
284 arrayTA[0] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
285 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
286 for (int i = 1; i <= 3; i++) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
287 at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
288 anno = at.getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
289 verifyTestAnn(arrayTA[i], anno, "array" + (i + 1)); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
290 arrayTA[i] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
291 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
292 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
293 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
294 private void verifyMapFieldTypeAnnotations(Class c) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
295 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
296 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
297 Annotation anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
298 AnnotatedType atBase; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
299 AnnotatedType atParameter; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
300 atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
301 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
302 anno = atBase.getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
303 verifyTestAnn(mapTA[0], anno, "map1"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
304 mapTA[0] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
305 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
306 atParameter = |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
307 ((AnnotatedParameterizedType) atBase). |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
308 getAnnotatedActualTypeArguments()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
309 anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
310 verifyTestAnn(mapTA[1], anno, "map2"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
311 mapTA[1] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
312 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
313 anno = |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
314 ((AnnotatedWildcardType) atParameter). |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
315 getAnnotatedUpperBounds()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
316 verifyTestAnn(mapTA[2], anno, "map3"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
317 mapTA[2] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
318 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
319 atParameter = |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
320 ((AnnotatedParameterizedType) atBase). |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
321 getAnnotatedActualTypeArguments()[1]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
322 anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
323 verifyTestAnn(mapTA[3], anno, "map4"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
324 mapTA[3] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
325 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
326 anno = |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
327 ((AnnotatedParameterizedType) atParameter). |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
328 getAnnotatedActualTypeArguments()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
329 verifyTestAnn(mapTA[4], anno, "map5"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
330 mapTA[4] = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
331 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
332 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
333 private void verifyMethodTypeAnnotations(Class c) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
334 throws NoSuchFieldException, NoSuchMethodException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
335 Annotation anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
336 Executable typeAnnotatedMethod = |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
337 c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
338 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
339 anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
340 verifyTestAnn(returnTA, anno, "return"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
341 returnTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
342 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
343 anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
344 verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
345 methodTypeParameterTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
346 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
347 anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
348 verifyTestAnn(formalParameterTA, anno, "formalParameter"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
349 formalParameterTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
350 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
351 anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0]; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
352 verifyTestAnn(throwsTA, anno, "throws"); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
353 throwsTA = anno; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
354 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
355 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
356 private static void verifyTestAnn(Annotation verifyAgainst, Annotation anno, String expectedSite) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
357 verifyTestAnnSite(anno, expectedSite); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
358 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
359 // When called before transform verifyAgainst will be null, when called |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
360 // after transform it will be the annotation from before the transform |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
361 if (verifyAgainst != null) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
362 assertTrue(anno.equals(verifyAgainst), |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
363 "Annotations do not match before and after." + |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
364 " Before: \"" + verifyAgainst + "\", After: \"" + anno + "\""); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
365 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
366 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
367 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
368 private static void verifyTestAnnSite(Annotation testAnn, String expectedSite) { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
369 String expectedAnn = "@TestAnn(site=" + expectedSite + ")"; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
370 assertTrue(testAnn.toString().equals(expectedAnn), |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
371 "Expected \"" + expectedAnn + "\", got \"" + testAnn + "\""); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
372 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
373 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
374 public static class TypeAnnotatedTestClass <@TestAnn(site="classTypeParameter") S,T> |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
375 extends @TestAnn(site="extends") Thread |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
376 implements @TestAnn(site="implements") Runnable { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
377 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
378 public @TestAnn(site="field") boolean typeAnnotatedBoolean; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
379 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
380 public |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
381 RedefineAnnotations. |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
382 @TestAnn(site="inner") TypeAnnotatedTestClass |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
383 typeAnnotatedInner; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
384 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
385 public |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
386 @TestAnn(site="array4") boolean |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
387 @TestAnn(site="array1") [] |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
388 @TestAnn(site="array2") [] |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
389 @TestAnn(site="array3") [] |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
390 typeAnnotatedArray; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
391 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
392 public @TestAnn(site="map1") Map |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
393 <@TestAnn(site="map2") ? extends @TestAnn(site="map3") String, |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
394 @TestAnn(site="map4") List<@TestAnn(site="map5") Object>> typeAnnotatedMap; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
395 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
396 public int dummy1; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
397 public int dummy2; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
398 public int dummy3; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
399 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
400 @TestAnn(site="return") <@TestAnn(site="methodTypeParameter") U,V> Class |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
401 typeAnnotatedMethod(@TestAnn(site="formalParameter") TypeAnnotatedTestClass arg) |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
402 throws @TestAnn(site="throws") ClassNotFoundException { |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
403 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
404 @TestAnn(site="local_variable_type") int foo = 0; |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
405 throw new ClassNotFoundException(); |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
406 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
407 |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
408 public void run() {} |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
409 } |
50054b63f0aa
8057043: Type annotations not retained during class redefine / retransform
aeriksso
parents:
diff
changeset
|
410 } |