Skip to content

Commit

Permalink
do not use JAVA_VERSION for runtime version check
Browse files Browse the repository at this point in the history
this constant is changeable using -Xbytecode.version=9
so its poorly named, use safer detection of Java 9+

follow-up on GH-5462
(merged from f8899fc)
  • Loading branch information
kares committed Dec 27, 2018
1 parent 05ddc0b commit 1d0c3d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -1645,7 +1645,7 @@ public boolean shouldPrecompileAll() {
/**
* The version to use for generated classes. Set to current JVM version by default
*/
public static final int JAVA_VERSION = initGlobalJavaVersion();
public static final int JAVA_VERSION = initJavaBytecodeVersion();

/**
* The number of lines at which a method, class, or block body is split into
Expand Down Expand Up @@ -1877,7 +1877,7 @@ public boolean shouldPrecompileAll() {
// Static initializers
////////////////////////////////////////////////////////////////////////////

private static int initGlobalJavaVersion() {
private static int initJavaBytecodeVersion() {
final String specVersion = Options.BYTECODE_VERSION.load();
switch ( specVersion ) {
case "1.6" :
Expand Down
17 changes: 14 additions & 3 deletions core/src/main/java/org/jruby/util/SecurityHelper.java
Expand Up @@ -8,18 +8,29 @@
import java.lang.reflect.Modifier;
import java.security.Security;

import static org.jruby.RubyInstanceConfig.JAVA_VERSION;

public abstract class SecurityHelper {

private static final Logger LOG = LoggerFactory.getLogger(SecurityHelper.class);
private static boolean attempted = false;

private static final boolean JAVA9;
static {
boolean versionClassFound;
try {
Class.forName("java.lang.Runtime.Version");
versionClassFound = true;
}
catch (Exception notFound) {
versionClassFound = false;
}
JAVA9 = versionClassFound;
}

// attempt to enable unlimited-strength crypto on OracleJDK
public static void checkCryptoRestrictions(final Ruby runtime) {
if ( ! attempted ) {
attempted = true;
if ( JAVA_VERSION >= 53 ) {
if ( JAVA9 ) {
setNonRestrictedJava9();
}
else {
Expand Down

0 comments on commit 1d0c3d6

Please sign in to comment.