Skip to content

Commit

Permalink
Disable setAccessible in JI when on Java 9.
Browse files Browse the repository at this point in the history
Java 9's module system requires us to do a bit more work to
set methods accessible within java.lang and other modules. If we
fail to do this, the method raises InaccessibleObjectException,
a Java 9-specific exception we can't catch in Java 8 code. For the
moment we will disable setAccessible use on Java 9 so JRuby can
start up and run correctly.
  • Loading branch information
headius committed Jan 19, 2017
1 parent 6926296 commit afe3b28
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.util.cli;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -187,7 +188,7 @@ public class Options {
public static final Option<Boolean> DUMP_INSTANCE_VARS = bool(DEBUG, "dump.variables", false, "Dump class + instance var names on first new of Object subclasses.");
public static final Option<Boolean> REWRITE_JAVA_TRACE = bool(DEBUG, "rewrite.java.trace", true, "Rewrite stack traces from exceptions raised in Java calls.");

public static final Option<Boolean> JI_SETACCESSIBLE = bool(JAVA_INTEGRATION, "ji.setAccessible", true, "Try to set inaccessible Java methods to be accessible.");
public static final Option<Boolean> JI_SETACCESSIBLE = bool(JAVA_INTEGRATION, "ji.setAccessible", calculateSetAccessibleDefault(), "Try to set inaccessible Java methods to be accessible.");
public static final Option<Boolean> JI_LOGCANSETACCESSIBLE = bool(JAVA_INTEGRATION, "ji.logCanSetAccessible", false, "Log whether setAccessible is working.");
public static final Option<Boolean> JI_UPPER_CASE_PACKAGE_NAME_ALLOWED = bool(JAVA_INTEGRATION, "ji.upper.case.package.name.allowed", false, "Allow Capitalized Java package names.");
public static final Option<Boolean> INTERFACES_USEPROXY = bool(JAVA_INTEGRATION, "interfaces.useProxy", false, "Use java.lang.reflect.Proxy for interface impl.");
Expand Down Expand Up @@ -285,6 +286,15 @@ private static boolean calculateInvokedynamicDefault() {
return false;
}

/**
* Java 9 has much more restrictive reflection access to e.g. java.lang classes, and raises a Java 9-specific
* error. For now we default ji.setAccessible to false so we don't attempt it.
*/
private static boolean calculateSetAccessibleDefault() {
String version = SafePropertyAccessor.getProperty("java.specification.version", "1.7");
return new BigDecimal(version).compareTo(new BigDecimal("1.9")) < 0;
}

private enum SearchMode { PREFIX, CONTAINS }

public static void listPrefix(String prefix) {
Expand Down

0 comments on commit afe3b28

Please sign in to comment.