@@ -380,7 +380,7 @@ private void resolveCreators()
380
380
List <AnnotatedMethod > creatorMethods = null ;
381
381
382
382
// Then static methods which are potential factory methods
383
- for (Method m : _class . getDeclaredMethods ( )) {
383
+ for (Method m : _findClassMethods ( _class )) {
384
384
if (!Modifier .isStatic (m .getModifiers ())) {
385
385
continue ;
386
386
}
@@ -411,7 +411,7 @@ private void resolveCreators()
411
411
}
412
412
_creatorsResolved = true ;
413
413
}
414
-
414
+
415
415
/**
416
416
* Method for resolving member method information: aggregating all non-static methods
417
417
* and combining annotations (to implement method-annotation inheritance)
@@ -598,9 +598,8 @@ protected void _addMemberMethods(Class<?> cls, AnnotatedMethodMap methods,
598
598
if (cls == null ) { // just so caller need not check when passing super-class
599
599
return ;
600
600
}
601
-
602
601
// then methods from the class itself
603
- for (Method m : cls . getDeclaredMethods ( )) {
602
+ for (Method m : _findClassMethods ( cls )) {
604
603
if (!_isIncludableMemberMethod (m )) {
605
604
continue ;
606
605
}
@@ -1016,6 +1015,37 @@ private final boolean _isAnnotationBundle(Annotation ann) {
1016
1015
return (_annotationIntrospector != null ) && _annotationIntrospector .isAnnotationBundle (ann );
1017
1016
}
1018
1017
1018
+ /**
1019
+ * Helper method that gets methods declared in given class; usually a simple thing,
1020
+ * but sometimes (as per [databind#785]) more complicated, depending on classloader
1021
+ * setup.
1022
+ *
1023
+ * @since 2.4.7
1024
+ */
1025
+ protected Method [] _findClassMethods (Class <?> cls )
1026
+ {
1027
+ try {
1028
+ return cls .getDeclaredMethods ();
1029
+ } catch (final NoClassDefFoundError ex ) {
1030
+ // One of the methods had a class that was not found in the cls.getClassLoader.
1031
+ // Maybe the developer was nice and has a different class loader for this context.
1032
+ final ClassLoader loader = Thread .currentThread ().getContextClassLoader ();
1033
+ if (loader == null ){
1034
+ // Nope... this is going to end poorly
1035
+ throw ex ;
1036
+ }
1037
+ final Class <?> contextClass ;
1038
+ try {
1039
+ contextClass = loader .loadClass (cls .getName ());
1040
+ } catch (ClassNotFoundException e ) {
1041
+ // !!! TODO: 08-May-2015, tatu: Chain appropriately once we have JDK7 as baseline
1042
+ //ex.addSuppressed(e); Not until 1.7
1043
+ throw ex ;
1044
+ }
1045
+ return contextClass .getDeclaredMethods (); // Cross fingers
1046
+ }
1047
+ }
1048
+
1019
1049
/*
1020
1050
/**********************************************************
1021
1051
/* Other methods
0 commit comments