Skip to content

Commit 7db1f44

Browse files
committed
Update release notes wrt #785, minor refactoring
1 parent afb688a commit 7db1f44

File tree

3 files changed

+46
-53
lines changed

3 files changed

+46
-53
lines changed

release-notes/CREDITS

+5
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ Eugene Lukash
157157
Fernando Otero (zeitos@github)
158158
* Contributed fix for #610: Problem with forward reference in hierarchies
159159
(2.4.4)
160+
161+
Charles Allen:
162+
* Contributed #785: Add handlings for classes which are available in
163+
`Thread.currentThread().getContextClassLoader()`
164+
(2.5.4)

release-notes/VERSION

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
2.4.7 (not yet released)
7+
2.4.6.1 (not yet released)
88

99
#676: Deserialization of class with generic collection inside depends on
1010
how is was deserialized first time
11+
#785: Add handlings for classes which are available in `Thread.currentThread().getContextClassLoader()`
12+
(contributed by Charles A)
1113

1214
2.4.6 (23-Apr-2015)
1315

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java

+38-52
Original file line numberDiff line numberDiff line change
@@ -378,30 +378,7 @@ private void resolveCreators()
378378
List<AnnotatedMethod> creatorMethods = null;
379379

380380
// Then static methods which are potential factory methods
381-
382-
Method[] classMethods;
383-
try{
384-
classMethods = _class.getDeclaredMethods();
385-
}catch(final NoClassDefFoundError ex){
386-
// One of the methods had a class that was not found in the cls.getClassLoader.
387-
// Maybe the developer was nice and has a different class loader for this context.
388-
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
389-
if(loader == null){
390-
// Nope... this is going to end poorly
391-
throw ex;
392-
}
393-
final Class<?> contextClass;
394-
try {
395-
contextClass = loader.loadClass(_class.getName());
396-
}
397-
catch (ClassNotFoundException e) {
398-
//ex.addSuppressed(e); Not until 1.7
399-
throw ex;
400-
}
401-
classMethods = contextClass.getDeclaredMethods(); // Cross fingers
402-
}
403-
404-
for (Method m : classMethods) {
381+
for (Method m : _findClassMethods(_class)) {
405382
if (!Modifier.isStatic(m.getModifiers())) {
406383
continue;
407384
}
@@ -432,7 +409,7 @@ private void resolveCreators()
432409
}
433410
_creatorsResolved = true;
434411
}
435-
412+
436413
/**
437414
* Method for resolving member method information: aggregating all non-static methods
438415
* and combining annotations (to implement method-annotation inheritance)
@@ -619,29 +596,8 @@ protected void _addMemberMethods(Class<?> cls, AnnotatedMethodMap methods,
619596
if (cls == null) { // just so caller need not check when passing super-class
620597
return;
621598
}
622-
Method[] classMethods;
623-
try{
624-
classMethods = cls.getDeclaredMethods();
625-
}catch(final NoClassDefFoundError ex){
626-
// One of the methods had a class that was not found in the cls.getClassLoader.
627-
// Maybe the developer was nice and has a different class loader for this context.
628-
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
629-
if (loader == null) {
630-
// Nope... this is going to end poorly
631-
throw ex;
632-
}
633-
final Class<?> contextClass;
634-
try {
635-
contextClass = loader.loadClass(cls.getName());
636-
}
637-
catch (ClassNotFoundException e) {
638-
//ex.addSuppressed(e); Not until 1.7
639-
throw ex;
640-
}
641-
classMethods = contextClass.getDeclaredMethods(); // Cross fingers
642-
}
643599
// then methods from the class itself
644-
for (Method m : classMethods) {
600+
for (Method m : _findClassMethods(cls)) {
645601
if (!_isIncludableMemberMethod(m)) {
646602
continue;
647603
}
@@ -1056,11 +1012,41 @@ protected void _addMixUnders(Method src, AnnotatedMethod target) {
10561012
_addAnnotationsIfNotPresent(target, src.getDeclaredAnnotations());
10571013
}
10581014

1059-
private final boolean _isAnnotationBundle(Annotation ann)
1060-
{
1061-
return (_annotationIntrospector != null) && _annotationIntrospector.isAnnotationBundle(ann);
1062-
}
1063-
1015+
private final boolean _isAnnotationBundle(Annotation ann) {
1016+
return (_annotationIntrospector != null) && _annotationIntrospector.isAnnotationBundle(ann);
1017+
}
1018+
1019+
/**
1020+
* Helper method that gets methods declared in given class; usually a simple thing,
1021+
* but sometimes (as per [databind#785]) more complicated, depending on classloader
1022+
* setup.
1023+
*
1024+
* @since 2.4.7
1025+
*/
1026+
protected Method[] _findClassMethods(Class<?> cls)
1027+
{
1028+
try {
1029+
return cls.getDeclaredMethods();
1030+
} catch (final NoClassDefFoundError ex) {
1031+
// One of the methods had a class that was not found in the cls.getClassLoader.
1032+
// Maybe the developer was nice and has a different class loader for this context.
1033+
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
1034+
if(loader == null){
1035+
// Nope... this is going to end poorly
1036+
throw ex;
1037+
}
1038+
final Class<?> contextClass;
1039+
try {
1040+
contextClass = loader.loadClass(cls.getName());
1041+
} catch (ClassNotFoundException e) {
1042+
// !!! TODO: 08-May-2015, tatu: Chain appropriately once we have JDK7 as baseline
1043+
//ex.addSuppressed(e); Not until 1.7
1044+
throw ex;
1045+
}
1046+
return contextClass.getDeclaredMethods(); // Cross fingers
1047+
}
1048+
}
1049+
10641050
/*
10651051
/**********************************************************
10661052
/* Other methods

0 commit comments

Comments
 (0)