Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 778532089419
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 755fdb7612f6
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Dec 15, 2016

  1. Test if we can set accessible by trying to call AccessibleObject#setA…

    …ccessible(boolean) instead of seeing if we have permission 'suppressAccessChecks'. We may not have that permission if we're not using a privileged classloader but can still setAccessible if (when) there's no security manager
    jmiettinen committed Dec 15, 2016
    Copy the full SHA
    592707d View commit details
  2. Copy the full SHA
    c54b9e4 View commit details
  3. Merge pull request #4389 from jmiettinen/check_accessible

    Check permission to AccessibleObject#setAccessible(boolean) a better way
    headius authored Dec 15, 2016
    Copy the full SHA
    755fdb7 View commit details
Showing with 18 additions and 5 deletions.
  1. +11 −0 core/src/main/java/org/jruby/javasupport/DummyForJavaUtil.java
  2. +7 −5 core/src/main/java/org/jruby/javasupport/JavaUtil.java
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/javasupport/DummyForJavaUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jruby.javasupport;

/**
* This class exists only for access-checks to set {@linkplain JavaUtil#CAN_SET_ACCESSIBLE}
*/
public class DummyForJavaUtil {

private static final Object PRIVATE = new Object[0];
public static final Object PUBLIC = PRIVATE;

}
12 changes: 7 additions & 5 deletions core/src/main/java/org/jruby/javasupport/JavaUtil.java
Original file line number Diff line number Diff line change
@@ -36,10 +36,10 @@
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ReflectPermission;
import static java.lang.Character.isLetter;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
@@ -48,7 +48,6 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.AccessController;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
@@ -99,9 +98,12 @@ public class JavaUtil {

if (RubyInstanceConfig.CAN_SET_ACCESSIBLE) {
try {
AccessController.checkPermission(new ReflectPermission("suppressAccessChecks"));
canSetAccessible = true;
} catch (Throwable t) {
// We want to check if we can access a commonly-existing private field through reflection. If so,
// we're probably able to access some other fields too later on.
Field f = DummyForJavaUtil.class.getDeclaredField("PRIVATE");
f.setAccessible(true);
canSetAccessible = f.get(null).equals(DummyForJavaUtil.PUBLIC);
} catch (Exception t) {
// added this so if things are weird in the future we can debug without
// spinning a new binary
if (Options.JI_LOGCANSETACCESSIBLE.load()) {