Skip to content

Commit

Permalink
Only try setAccessible for elements that are not currently.
Browse files Browse the repository at this point in the history
This reduces likelihood of hitting issues on Java 9 and may also
reduce boot overhead due to fewer security checks.
  • Loading branch information
headius committed Aug 24, 2016
1 parent 84b12e7 commit 7df6090
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -279,7 +279,8 @@ static JavaProxy castJavaProxy(final IRubyObject self) {
}

static <T extends AccessibleObject> T setAccessible(T accessible) {
if ( ! Ruby.isSecurityRestricted() ) {
if (!accessible.isAccessible() &&
!Ruby.isSecurityRestricted() ) {
try { accessible.setAccessible(true); }
catch (SecurityException e) {}
catch (RuntimeException re) {
@@ -300,7 +301,8 @@ private static void rethrowIfNotInaccessibleObject(RuntimeException re) {
}

static <T extends AccessibleObject> T[] setAccessible(T[] accessibles) {
if ( ! Ruby.isSecurityRestricted() ) {
if (!allAreAccessible(accessibles) &&
!Ruby.isSecurityRestricted() ) {
try { AccessibleObject.setAccessible(accessibles, true); }
catch (SecurityException e) {}
catch (RuntimeException re) {
@@ -310,6 +312,11 @@ static <T extends AccessibleObject> T[] setAccessible(T[] accessibles) {
return accessibles;
}

private static <T extends AccessibleObject> boolean allAreAccessible(T[] accessibles) {
for (T accessible : accessibles) if (!accessible.isAccessible()) return false;
return true;
}

protected T findCallable(IRubyObject self, String name, IRubyObject[] args, final int arity) {
switch (arity) {
case 0:

0 comments on commit 7df6090

Please sign in to comment.