Skip to content

Commit b56e779

Browse files
ClassUtil.checkAndFixAccess: ignore errors re: setAccessible, it's very common in JPMS world
1 parent 6af6725 commit b56e779

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

Diff for: src/main/java/tools/jackson/databind/util/ClassUtil.java

+6-25
Original file line numberDiff line numberDiff line change
@@ -846,41 +846,22 @@ public static boolean checkAndFixAccess(Member member, boolean evenIfAlreadyPubl
846846
// We know all members are also accessible objects...
847847
AccessibleObject ao = (AccessibleObject) member;
848848

849-
// 14-Jan-2009, tatu: It seems safe and potentially beneficial to
850-
// always to make it accessible (latter because it will force
851-
// skipping checks we have no use for...), so let's always call it.
852849
try {
853850
// 15-Apr-2021, tatu: With JDK 14+ we will be hitting access limitations
854851
// esp. wrt JDK types so let's change a bit
855852
final Class<?> declaringClass = member.getDeclaringClass();
856853
boolean isPublic = Modifier.isPublic(member.getModifiers())
857854
&& Modifier.isPublic(declaringClass.getModifiers());
858855
if (!isJDKClass(declaringClass) && (!isPublic || evenIfAlreadyPublic)) {
859-
return ao.trySetAccessible();
856+
ao.setAccessible(true);
857+
return true;
860858
} else {
861859
return isPublic;
862860
}
863-
} catch (SecurityException se) {
864-
// 17-Apr-2009, tatu: This can fail on platforms like
865-
// Google App Engine); so let's only fail if we really needed it...
866-
if (!ao.isAccessible()) {
867-
Class<?> declClass = member.getDeclaringClass();
868-
throw new IllegalArgumentException("Cannot access "+member+" (from class "+declClass.getName()
869-
+"; failed to set access: "+exceptionMessage(se));
870-
}
871-
// 14-Apr-2021, tatu: [databind#3118] Java 9/JPMS causes new fails...
872-
// But while our baseline is Java 8, must check name
873-
return true;
874-
} catch (RuntimeException se) {
875-
if ("InaccessibleObjectException".equals(se.getClass().getSimpleName())) {
876-
throw new IllegalArgumentException(String.format(
877-
"Failed to call `setAccess()` on %s '%s' (of class %s) due to `%s`, problem: %s",
878-
member.getClass().getSimpleName(), member.getName(),
879-
nameOf(member.getDeclaringClass()),
880-
se.getClass().getName(), se.getMessage()),
881-
se);
882-
}
883-
throw se;
861+
} catch (InaccessibleObjectException | SecurityException e) {
862+
// 2025-03-24, scs: Since Java module system, it is common to be unable to see
863+
// members of other modules. We can't assume we can crack open arbitrary types anymore.
864+
return false;
884865
}
885866
}
886867

0 commit comments

Comments
 (0)