Skip to content

Commit

Permalink
Merge pull request #785 from drcrallen/jackson-databind-2.4.4-mmx
Browse files Browse the repository at this point in the history
Add handlings for classes which are available in `Thread.currentThread().getContextClassLoader()`
  • Loading branch information
cowtowncoder committed May 8, 2015
2 parents c5a5f53 + 3858853 commit afb688a
Showing 1 changed file with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,30 @@ private void resolveCreators()
List<AnnotatedMethod> creatorMethods = null;

// Then static methods which are potential factory methods
for (Method m : _class.getDeclaredMethods()) {

Method[] classMethods;
try{
classMethods = _class.getDeclaredMethods();
}catch(final NoClassDefFoundError ex){
// One of the methods had a class that was not found in the cls.getClassLoader.
// Maybe the developer was nice and has a different class loader for this context.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader == null){
// Nope... this is going to end poorly
throw ex;
}
final Class<?> contextClass;
try {
contextClass = loader.loadClass(_class.getName());
}
catch (ClassNotFoundException e) {
//ex.addSuppressed(e); Not until 1.7
throw ex;
}
classMethods = contextClass.getDeclaredMethods(); // Cross fingers
}

for (Method m : classMethods) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
Expand Down Expand Up @@ -596,9 +619,29 @@ protected void _addMemberMethods(Class<?> cls, AnnotatedMethodMap methods,
if (cls == null) { // just so caller need not check when passing super-class
return;
}

Method[] classMethods;
try{
classMethods = cls.getDeclaredMethods();
}catch(final NoClassDefFoundError ex){
// One of the methods had a class that was not found in the cls.getClassLoader.
// Maybe the developer was nice and has a different class loader for this context.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
// Nope... this is going to end poorly
throw ex;
}
final Class<?> contextClass;
try {
contextClass = loader.loadClass(cls.getName());
}
catch (ClassNotFoundException e) {
//ex.addSuppressed(e); Not until 1.7
throw ex;
}
classMethods = contextClass.getDeclaredMethods(); // Cross fingers
}
// then methods from the class itself
for (Method m : cls.getDeclaredMethods()) {
for (Method m : classMethods) {
if (!_isIncludableMemberMethod(m)) {
continue;
}
Expand Down

0 comments on commit afb688a

Please sign in to comment.