Skip to content

Commit

Permalink
Properly fall back if can't setAccessible
Browse files Browse the repository at this point in the history
Changes in e8dbe9c broke this fallback by silencing errors from
the old setAccessible (as part of becoming more module-friendly).
This patch checks if the setAccessible was successful and returns
null for any fields that could not be made accessible. This in
turn allows the USABLE fallback to properly reflect actual
usability.
  • Loading branch information
headius committed Jun 27, 2024
1 parent e035e16 commit 33e821e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ private static int readIntField(ByteArrayInputStream self, Field field) {
private static Field accessibleField(final String name) {
try {
Field field = ByteArrayInputStream.class.getDeclaredField(name);
Java.trySetAccessible(field);
return field;
if (Java.trySetAccessible(field)) {
return field;
}
}
catch (NoSuchFieldException ex) {
return null; // should never happen
// should never happen
}
catch (SecurityException ex) {
return null;
}

return null;
}

}

0 comments on commit 33e821e

Please sign in to comment.