Skip to content

Commit

Permalink
Tiny bit of protective checking in AnnotatedClass to help with pote…
Browse files Browse the repository at this point in the history
…ntial concurrency issue
  • Loading branch information
cowtowncoder committed Apr 8, 2017
1 parent 3cc6d84 commit 6b9782b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 4 additions & 0 deletions release-notes/VERSION
Expand Up @@ -4,6 +4,10 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.7.10 (not yet released)

- Minor robustification of method resolution in `AnnotatedClass`

2.7.9 (04-Feb-2017)

#1367: No Object Id found for an instance when using `@ConstructorProperties`
Expand Down
Expand Up @@ -116,7 +116,7 @@ public final class AnnotatedClass
* Member methods of interest; for now ones with 0 or 1 arguments
* (just optimization, since others won't be used now)
*/
protected AnnotatedMethodMap _memberMethods;
protected AnnotatedMethodMap _memberMethods;

/**
* Member fields of interest: ones that are either public,
Expand Down Expand Up @@ -520,23 +520,28 @@ private void resolveCreators()
*/
private void resolveMemberMethods()
{
_memberMethods = new AnnotatedMethodMap();
_memberMethods = _resolveMemberMethods();
}

private AnnotatedMethodMap _resolveMemberMethods()
{
AnnotatedMethodMap memberMethods = new AnnotatedMethodMap();
AnnotatedMethodMap mixins = new AnnotatedMethodMap();
// first: methods from the class itself
_addMemberMethods(_class, this, _memberMethods, _primaryMixIn, mixins);
_addMemberMethods(_class, this, memberMethods, _primaryMixIn, mixins);

// and then augment these with annotations from super-types:
for (JavaType type : _superTypes) {
Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(type.getRawClass());
_addMemberMethods(type.getRawClass(),
new TypeResolutionContext.Basic(_typeFactory, type.getBindings()),
_memberMethods, mixin, mixins);
memberMethods, mixin, mixins);
}
// Special case: mix-ins for Object.class? (to apply to ALL classes)
if (_mixInResolver != null) {
Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class);
if (mixin != null) {
_addMethodMixIns(_class, _memberMethods, mixin, mixins);
_addMethodMixIns(_class, memberMethods, mixin, mixins);
}
}

Expand All @@ -557,14 +562,15 @@ private void resolveMemberMethods()
// Since it's from java.lang.Object, no generics, no need for real type context:
AnnotatedMethod am = _constructMethod(m, this);
_addMixOvers(mixIn.getAnnotated(), am, false);
_memberMethods.add(am);
memberMethods.add(am);
}
} catch (Exception e) { }
}
}
}
return memberMethods;
}

/**
* Method that will collect all member (non-static) fields
* that are either public, or have at least a single annotation
Expand All @@ -573,14 +579,16 @@ private void resolveMemberMethods()
private void resolveFields()
{
Map<String,AnnotatedField> foundFields = _findFields(_type, this, null);
List<AnnotatedField> f;
if (foundFields == null || foundFields.size() == 0) {
_fields = Collections.emptyList();
f = Collections.emptyList();
} else {
_fields = new ArrayList<AnnotatedField>(foundFields.size());
_fields.addAll(foundFields.values());
f = new ArrayList<AnnotatedField>(foundFields.size());
f.addAll(foundFields.values());
}
_fields = f;
}

/*
/**********************************************************
/* Helper methods for resolving class annotations
Expand Down

0 comments on commit 6b9782b

Please sign in to comment.