@@ -88,7 +88,7 @@ public final class AnnotatedClass
88
88
* Combined list of Jackson annotations that the class has,
89
89
* including inheritable ones from super classes and interfaces
90
90
*/
91
- protected AnnotationMap _classAnnotations ;
91
+ final protected AnnotationMap _classAnnotations ;
92
92
93
93
/**
94
94
* Flag to indicate whether creator information has been resolved
@@ -144,8 +144,7 @@ public final class AnnotatedClass
144
144
*/
145
145
private AnnotatedClass (JavaType type , Class <?> rawType , TypeBindings bindings ,
146
146
List <JavaType > superTypes ,
147
- AnnotationIntrospector aintr , MixInResolver mir , TypeFactory tf ,
148
- AnnotationMap classAnnotations )
147
+ AnnotationIntrospector aintr , MixInResolver mir , TypeFactory tf )
149
148
{
150
149
_type = type ;
151
150
_class = rawType ;
@@ -156,13 +155,24 @@ private AnnotatedClass(JavaType type, Class<?> rawType, TypeBindings bindings,
156
155
_mixInResolver = mir ;
157
156
_primaryMixIn = (_mixInResolver == null ) ? null
158
157
: _mixInResolver .findMixInClassFor (_class );
159
- _classAnnotations = classAnnotations ;
158
+ _classAnnotations = _resolveClassAnnotations ();
159
+ }
160
+
161
+ private AnnotatedClass (AnnotatedClass base , AnnotationMap clsAnn ) {
162
+ _type = base ._type ;
163
+ _class = base ._class ;
164
+ _bindings = base ._bindings ;
165
+ _superTypes = base ._superTypes ;
166
+ _annotationIntrospector = base ._annotationIntrospector ;
167
+ _typeFactory = base ._typeFactory ;
168
+ _mixInResolver = base ._mixInResolver ;
169
+ _primaryMixIn = base ._primaryMixIn ;
170
+ _classAnnotations = clsAnn ;
160
171
}
161
172
162
173
@ Override
163
174
public AnnotatedClass withAnnotations (AnnotationMap ann ) {
164
- return new AnnotatedClass (_type , _class , _bindings , _superTypes ,
165
- _annotationIntrospector , _mixInResolver , _typeFactory , ann );
175
+ return new AnnotatedClass (this , ann );
166
176
}
167
177
168
178
/**
@@ -178,7 +188,7 @@ public static AnnotatedClass construct(JavaType type, MapperConfig<?> config) {
178
188
Class <?> raw = type .getRawClass ();
179
189
return new AnnotatedClass (type , raw , type .getBindings (),
180
190
ClassUtil .findSuperTypes (type , null , false ), intr ,
181
- (MixInResolver ) config , config .getTypeFactory (), null );
191
+ (MixInResolver ) config , config .getTypeFactory ());
182
192
}
183
193
184
194
/**
@@ -192,7 +202,7 @@ public static AnnotatedClass construct(JavaType type, MapperConfig<?> config,
192
202
Class <?> raw = type .getRawClass ();
193
203
return new AnnotatedClass (type , raw , type .getBindings (),
194
204
ClassUtil .findSuperTypes (type , null , false ),
195
- intr , mir , config .getTypeFactory (), null );
205
+ intr , mir , config .getTypeFactory ());
196
206
}
197
207
198
208
/**
@@ -204,25 +214,25 @@ public static AnnotatedClass constructWithoutSuperTypes(Class<?> cls, MapperConf
204
214
{
205
215
if (config == null ) {
206
216
return new AnnotatedClass (null , cls , TypeBindings .emptyBindings (),
207
- Collections .<JavaType >emptyList (), null , null , null , null );
217
+ Collections .<JavaType >emptyList (), null , null , null );
208
218
}
209
219
AnnotationIntrospector intr = config .isAnnotationProcessingEnabled ()
210
220
? config .getAnnotationIntrospector () : null ;
211
221
return new AnnotatedClass (null , cls , TypeBindings .emptyBindings (),
212
- Collections .<JavaType >emptyList (), intr , (MixInResolver ) config , config .getTypeFactory (), null );
222
+ Collections .<JavaType >emptyList (), intr , (MixInResolver ) config , config .getTypeFactory ());
213
223
}
214
224
215
225
public static AnnotatedClass constructWithoutSuperTypes (Class <?> cls , MapperConfig <?> config ,
216
226
MixInResolver mir )
217
227
{
218
228
if (config == null ) {
219
229
return new AnnotatedClass (null , cls , TypeBindings .emptyBindings (),
220
- Collections .<JavaType >emptyList (), null , null , null , null );
230
+ Collections .<JavaType >emptyList (), null , null , null );
221
231
}
222
232
AnnotationIntrospector intr = config .isAnnotationProcessingEnabled ()
223
233
? config .getAnnotationIntrospector () : null ;
224
234
return new AnnotatedClass (null , cls , TypeBindings .emptyBindings (),
225
- Collections .<JavaType >emptyList (), intr , mir , config .getTypeFactory (), null );
235
+ Collections .<JavaType >emptyList (), intr , mir , config .getTypeFactory ());
226
236
}
227
237
228
238
/*
@@ -253,17 +263,17 @@ public JavaType resolveType(Type type) {
253
263
254
264
@ Override
255
265
public <A extends Annotation > A getAnnotation (Class <A > acls ) {
256
- return _classAnnotations () .get (acls );
266
+ return _classAnnotations .get (acls );
257
267
}
258
268
259
269
@ Override
260
270
public boolean hasAnnotation (Class <?> acls ) {
261
- return _classAnnotations () .has (acls );
271
+ return _classAnnotations .has (acls );
262
272
}
263
273
264
274
@ Override
265
275
public boolean hasOneOf (Class <? extends Annotation >[] annoClasses ) {
266
- return _classAnnotations () .hasOneOf (annoClasses );
276
+ return _classAnnotations .hasOneOf (annoClasses );
267
277
}
268
278
269
279
@ Override
@@ -273,12 +283,12 @@ public Class<?> getRawType() {
273
283
274
284
@ Override
275
285
public Iterable <Annotation > annotations () {
276
- return _classAnnotations () .annotations ();
286
+ return _classAnnotations .annotations ();
277
287
}
278
288
279
289
@ Override
280
290
protected AnnotationMap getAllAnnotations () {
281
- return _classAnnotations () ;
291
+ return _classAnnotations ;
282
292
}
283
293
284
294
@ Override
@@ -293,11 +303,11 @@ public JavaType getType() {
293
303
*/
294
304
295
305
public Annotations getAnnotations () {
296
- return _classAnnotations () ;
306
+ return _classAnnotations ;
297
307
}
298
308
299
309
public boolean hasAnnotations () {
300
- return _classAnnotations () .size () > 0 ;
310
+ return _classAnnotations .size () > 0 ;
301
311
}
302
312
303
313
public AnnotatedConstructor getDefaultConstructor ()
@@ -381,26 +391,6 @@ public boolean isNonStaticInnerClass()
381
391
/**********************************************************
382
392
*/
383
393
384
- private AnnotationMap _classAnnotations () {
385
- AnnotationMap anns = _classAnnotations ;
386
- if (anns == null ) {
387
- // 06-Dec-2015, tatu: yes, double-locking, typically not a good choice.
388
- // But for typical usage pattern here (and with JVM 7 and above) is
389
- // a reasonable choice to avoid non-common but existing race condition
390
- // from root name lookup style usage
391
- // Also note that race condition stems from caching only used for loading
392
- // where just class annotations are needed
393
- synchronized (this ) {
394
- anns = _classAnnotations ;
395
- if (anns == null ) {
396
- anns = _resolveClassAnnotations ();
397
- _classAnnotations = anns ;
398
- }
399
- }
400
- }
401
- return anns ;
402
- }
403
-
404
394
/**
405
395
* Initialization method that will recursively collect Jackson
406
396
* annotations for this class and all super classes and
0 commit comments