@@ -846,41 +846,22 @@ public static boolean checkAndFixAccess(Member member, boolean evenIfAlreadyPubl
846
846
// We know all members are also accessible objects...
847
847
AccessibleObject ao = (AccessibleObject ) member ;
848
848
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.
852
849
try {
853
850
// 15-Apr-2021, tatu: With JDK 14+ we will be hitting access limitations
854
851
// esp. wrt JDK types so let's change a bit
855
852
final Class <?> declaringClass = member .getDeclaringClass ();
856
853
boolean isPublic = Modifier .isPublic (member .getModifiers ())
857
854
&& Modifier .isPublic (declaringClass .getModifiers ());
858
855
if (!isJDKClass (declaringClass ) && (!isPublic || evenIfAlreadyPublic )) {
859
- return ao .trySetAccessible ();
856
+ ao .setAccessible (true );
857
+ return true ;
860
858
} else {
861
859
return isPublic ;
862
860
}
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 ;
884
865
}
885
866
}
886
867
0 commit comments