@@ -1756,56 +1756,57 @@ private void populateMap(Object bean, Set<Object> objectsRecord) {
1756
1756
Class <?> klass = bean .getClass ();
1757
1757
1758
1758
// If klass is a System class then set includeSuperClass to false.
1759
-
1760
1759
boolean includeSuperClass = klass .getClassLoader () != null ;
1761
1760
1762
1761
Method [] methods = includeSuperClass ? klass .getMethods () : klass .getDeclaredMethods ();
1763
1762
for (final Method method : methods ) {
1764
- final int modifiers = method .getModifiers ();
1765
- if (Modifier .isPublic (modifiers )
1766
- && !Modifier .isStatic (modifiers )
1767
- && method .getParameterTypes ().length == 0
1768
- && !method .isBridge ()
1769
- && method .getReturnType () != Void .TYPE
1770
- && isValidMethodName (method .getName ())) {
1763
+ if (isEligibleMethod (method )) {
1771
1764
final String key = getKeyNameFromMethod (method );
1772
- if (key != null && ! key . isEmpty ( )) {
1765
+ if (isValidKey ( key )) {
1773
1766
try {
1774
1767
final Object result = method .invoke (bean );
1775
1768
if (result != null ) {
1776
- // check cyclic dependency and throw error if needed
1777
- // the wrap and populateMap combination method is
1778
- // itself DFS recursive
1779
- if (objectsRecord .contains (result )) {
1780
- throw recursivelyDefinedObjectException (key );
1781
- }
1782
-
1783
- objectsRecord .add (result );
1784
-
1785
- testValidity (result );
1786
- this .map .put (key , wrap (result , objectsRecord ));
1787
-
1788
- objectsRecord .remove (result );
1789
-
1790
- // we don't use the result anywhere outside of wrap
1791
- // if it's a resource we should be sure to close it
1792
- // after calling toString
1793
- if (result instanceof Closeable ) {
1794
- try {
1795
- ((Closeable ) result ).close ();
1796
- } catch (IOException ignore ) {
1797
- }
1798
- }
1769
+ processResult (bean , objectsRecord , key , result );
1799
1770
}
1800
- } catch (IllegalAccessException ignore ) {
1801
- } catch (IllegalArgumentException ignore ) {
1802
- } catch (InvocationTargetException ignore ) {
1771
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ignore ) {
1803
1772
}
1804
1773
}
1805
1774
}
1806
1775
}
1807
1776
}
1808
1777
1778
+ private boolean isEligibleMethod (Method method ) {
1779
+ final int modifiers = method .getModifiers ();
1780
+ return Modifier .isPublic (modifiers )
1781
+ && !Modifier .isStatic (modifiers )
1782
+ && method .getParameterTypes ().length == 0
1783
+ && !method .isBridge ()
1784
+ && method .getReturnType () != Void .TYPE
1785
+ && isValidMethodName (method .getName ());
1786
+ }
1787
+
1788
+ private boolean isValidKey (String key ) {
1789
+ return key != null && !key .isEmpty ();
1790
+ }
1791
+
1792
+ private void processResult (Object bean , Set <Object > objectsRecord , String key , Object result ) throws IllegalAccessException , InvocationTargetException {
1793
+ if (objectsRecord .contains (result )) {
1794
+ throw recursivelyDefinedObjectException (key );
1795
+ }
1796
+
1797
+ objectsRecord .add (result );
1798
+ testValidity (result );
1799
+ this .map .put (key , wrap (result , objectsRecord ));
1800
+ objectsRecord .remove (result );
1801
+
1802
+ if (result instanceof Closeable ) {
1803
+ try {
1804
+ ((Closeable ) result ).close ();
1805
+ } catch (IOException ignore ) {
1806
+ }
1807
+ }
1808
+ }
1809
+
1809
1810
private static boolean isValidMethodName (String name ) {
1810
1811
return !"getClass" .equals (name ) && !"getDeclaringClass" .equals (name );
1811
1812
}
0 commit comments