author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
20180
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
1 |
/* |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
4 |
* |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
8 |
* |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
13 |
* accompanied this code). |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
14 |
* |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
18 |
* |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
21 |
* questions. |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
22 |
*/ |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
23 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
24 |
/* |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
25 |
* @test |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
26 |
* @bug 8011940 |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
27 |
* @summary Test inheritance, order and class redefinition behaviour of RUNTIME |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
28 |
* class annotations |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
29 |
* @author plevart |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
30820
diff
changeset
|
30 |
* @modules java.base/java.lang:open |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
30820
diff
changeset
|
31 |
* java.base/sun.reflect.annotation |
20180
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
32 |
*/ |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
33 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
34 |
import sun.reflect.annotation.AnnotationParser; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
35 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
36 |
import java.lang.annotation.Annotation; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
37 |
import java.lang.annotation.Inherited; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
38 |
import java.lang.annotation.Retention; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
39 |
import java.lang.annotation.RetentionPolicy; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
40 |
import java.lang.reflect.Field; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
41 |
import java.lang.reflect.InvocationTargetException; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
42 |
import java.util.ArrayList; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
43 |
import java.util.Arrays; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
44 |
import java.util.Collections; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
45 |
import java.util.List; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
46 |
import java.util.StringJoiner; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
47 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
48 |
public class AnnotationsInheritanceOrderRedefinitionTest { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
49 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
50 |
@Retention(RetentionPolicy.RUNTIME) |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
51 |
@Inherited |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
52 |
@interface Ann1 { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
53 |
String value(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
54 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
55 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
56 |
@Retention(RetentionPolicy.RUNTIME) |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
57 |
@Inherited |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
58 |
@interface Ann2 { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
59 |
String value(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
60 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
61 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
62 |
@Retention(RetentionPolicy.RUNTIME) |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
63 |
@Inherited |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
64 |
@interface Ann3 { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
65 |
String value(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
66 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
67 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
68 |
@Ann1("A") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
69 |
@Ann2("A") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
70 |
static class A {} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
71 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
72 |
@Ann3("B") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
73 |
static class B extends A {} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
74 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
75 |
@Ann1("C") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
76 |
@Ann3("C") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
77 |
static class C extends B {} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
78 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
79 |
public static void main(String[] args) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
80 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
81 |
StringBuilder msgs = new StringBuilder(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
82 |
boolean ok = true; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
83 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
84 |
ok &= annotationsEqual(msgs, A.class, true, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
85 |
ann(Ann1.class, "A"), ann(Ann2.class, "A")); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
86 |
ok &= annotationsEqual(msgs, A.class, false, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
87 |
ann(Ann1.class, "A"), ann(Ann2.class, "A")); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
88 |
ok &= annotationsEqual(msgs, B.class, true, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
89 |
ann(Ann3.class, "B")); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
90 |
ok &= annotationsEqual(msgs, B.class, false, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
91 |
ann(Ann1.class, "A"), ann(Ann2.class, "A"), ann(Ann3.class, "B")); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
92 |
ok &= annotationsEqual(msgs, C.class, true, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
93 |
ann(Ann1.class, "C"), ann(Ann3.class, "C")); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
94 |
ok &= annotationsEqual(msgs, C.class, false, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
95 |
ann(Ann1.class, "C"), ann(Ann2.class, "A"), ann(Ann3.class, "C")); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
96 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
97 |
Annotation[] declaredAnnotatiosA = A.class.getDeclaredAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
98 |
Annotation[] annotationsA = A.class.getAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
99 |
Annotation[] declaredAnnotatiosB = B.class.getDeclaredAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
100 |
Annotation[] annotationsB = B.class.getAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
101 |
Annotation[] declaredAnnotatiosC = C.class.getDeclaredAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
102 |
Annotation[] annotationsC = C.class.getAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
103 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
104 |
incrementClassRedefinedCount(A.class); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
105 |
incrementClassRedefinedCount(B.class); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
106 |
incrementClassRedefinedCount(C.class); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
107 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
108 |
ok &= annotationsEqualButNotSame(msgs, A.class, true, declaredAnnotatiosA); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
109 |
ok &= annotationsEqualButNotSame(msgs, A.class, false, annotationsA); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
110 |
ok &= annotationsEqualButNotSame(msgs, B.class, true, declaredAnnotatiosB); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
111 |
ok &= annotationsEqualButNotSame(msgs, B.class, false, annotationsB); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
112 |
ok &= annotationsEqualButNotSame(msgs, C.class, true, declaredAnnotatiosC); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
113 |
ok &= annotationsEqualButNotSame(msgs, C.class, false, annotationsC); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
114 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
115 |
if (!ok) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
116 |
throw new RuntimeException("test failure\n" + msgs); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
117 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
118 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
119 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
120 |
// utility methods |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
121 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
122 |
private static boolean annotationsEqualButNotSame(StringBuilder msgs, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
123 |
Class<?> declaringClass, boolean declaredOnly, Annotation[] oldAnns) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
124 |
if (!annotationsEqual(msgs, declaringClass, declaredOnly, oldAnns)) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
125 |
return false; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
126 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
127 |
Annotation[] anns = declaredOnly |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
128 |
? declaringClass.getDeclaredAnnotations() |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
129 |
: declaringClass.getAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
130 |
List<Annotation> sameAnns = new ArrayList<>(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
131 |
for (int i = 0; i < anns.length; i++) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
132 |
if (anns[i] == oldAnns[i]) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
133 |
sameAnns.add(anns[i]); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
134 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
135 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
136 |
if (!sameAnns.isEmpty()) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
137 |
msgs.append(declaredOnly ? "declared " : "").append("annotations for ") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
138 |
.append(declaringClass.getSimpleName()) |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
139 |
.append(" not re-parsed after class redefinition: ") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
140 |
.append(toSimpleString(sameAnns)).append("\n"); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
141 |
return false; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
142 |
} else { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
143 |
return true; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
144 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
145 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
146 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
147 |
private static boolean annotationsEqual(StringBuilder msgs, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
148 |
Class<?> declaringClass, boolean declaredOnly, Annotation... expectedAnns) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
149 |
Annotation[] anns = declaredOnly |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
150 |
? declaringClass.getDeclaredAnnotations() |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
151 |
: declaringClass.getAnnotations(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
152 |
if (!Arrays.equals(anns, expectedAnns)) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
153 |
msgs.append(declaredOnly ? "declared " : "").append("annotations for ") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
154 |
.append(declaringClass.getSimpleName()).append(" are: ") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
155 |
.append(toSimpleString(anns)).append(", expected: ") |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
156 |
.append(toSimpleString(expectedAnns)).append("\n"); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
157 |
return false; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
158 |
} else { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
159 |
return true; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
160 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
161 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
162 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
163 |
private static Annotation ann(Class<? extends Annotation> annotationType, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
164 |
Object value) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
165 |
return AnnotationParser.annotationForMap(annotationType, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
166 |
Collections.singletonMap("value", value)); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
167 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
168 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
169 |
private static String toSimpleString(List<Annotation> anns) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
170 |
return toSimpleString(anns.toArray(new Annotation[anns.size()])); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
171 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
172 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
173 |
private static String toSimpleString(Annotation[] anns) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
174 |
StringJoiner joiner = new StringJoiner(", "); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
175 |
for (Annotation ann : anns) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
176 |
joiner.add(toSimpleString(ann)); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
177 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
178 |
return joiner.toString(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
179 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
180 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
181 |
private static String toSimpleString(Annotation ann) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
182 |
Class<? extends Annotation> annotationType = ann.annotationType(); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
183 |
Object value; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
184 |
try { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
185 |
value = annotationType.getDeclaredMethod("value").invoke(ann); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
186 |
} catch (IllegalAccessException | InvocationTargetException |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
187 |
| NoSuchMethodException e) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
188 |
throw new RuntimeException(e); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
189 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
190 |
return "@" + annotationType.getSimpleName() + "(" + value + ")"; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
191 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
192 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
193 |
private static final Field classRedefinedCountField; |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
194 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
195 |
static { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
196 |
try { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
197 |
classRedefinedCountField = Class.class.getDeclaredField("classRedefinedCount"); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
198 |
classRedefinedCountField.setAccessible(true); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
199 |
} catch (NoSuchFieldException e) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
200 |
throw new Error(e); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
201 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
202 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
203 |
|
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
204 |
private static void incrementClassRedefinedCount(Class<?> clazz) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
205 |
try { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
206 |
classRedefinedCountField.set(clazz, |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
207 |
((Integer) classRedefinedCountField.get(clazz)) + 1); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
208 |
} catch (IllegalAccessException e) { |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
209 |
throw new RuntimeException(e); |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
210 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
211 |
} |
0dedfb3744f2
8011940: java.lang.Class.getAnnotations() always enters synchronized method
plevart
parents:
diff
changeset
|
212 |
} |