Skip to content

Instantly share code, notes, and snippets.

@headius
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/ade87821600f75f10f74 to your computer and use it in GitHub Desktop.
Save headius/ade87821600f75f10f74 to your computer and use it in GitHub Desktop.
diff --git a/core/src/main/java/org/jruby/RubyInstanceConfig.java b/core/src/main/java/org/jruby/RubyInstanceConfig.java
index 02b580b..9a8a1e4 100644
--- a/core/src/main/java/org/jruby/RubyInstanceConfig.java
+++ b/core/src/main/java/org/jruby/RubyInstanceConfig.java
@@ -1865,7 +1865,8 @@ public class RubyInstanceConfig {
} else if (specDecimal.compareTo(BIGDECIMAL_1_5) >= 0) {
return Opcodes.V1_5;
} else {
- throw new RuntimeException("unsupported Java version: " + specVersion);
+ System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.5");
+ return Opcodes.V1_5;
}
}
diff --git a/core/src/main/java/org/jruby/compiler/impl/StandardASMCompiler.java b/core/src/main/java/org/jruby/compiler/impl/StandardASMCompiler.java
index ddb0002..4622e62 100644
--- a/core/src/main/java/org/jruby/compiler/impl/StandardASMCompiler.java
+++ b/core/src/main/java/org/jruby/compiler/impl/StandardASMCompiler.java
@@ -520,11 +520,21 @@ public class StandardASMCompiler implements ScriptCompiler, Opcodes {
SkinnyMethodAdapter method = new SkinnyMethodAdapter(getClassVisitor(), ACC_PUBLIC | ACC_STATIC, "main", sig(Void.TYPE, params(String[].class)), null, null);
method.start();
+ // init script filename to simple class name in case we don't assign it (null ClassLoader)
+ method.ldc(getClassname().replaceAll("\\\\.", "/"));
+ method.astore(1);
+
// new instance to invoke run against
method.newobj(getClassname());
method.dup();
method.invokespecial(getClassname(), "<init>", sig(Void.TYPE));
+ // guard against null classloader
+ method.ldc(Type.getType("L" + getClassname() + ";"));
+ method.invokevirtual(p(Class.class), "getClassLoader", sig(ClassLoader.class));
+ Label skip = new Label();
+ method.ifnull(skip);
+
// set filename for the loaded script class (JRUBY-4825)
method.dup();
method.ldc(Type.getType("L" + getClassname() + ";"));
@@ -536,6 +546,9 @@ public class StandardASMCompiler implements ScriptCompiler, Opcodes {
method.aload(1);
method.invokevirtual(p(AbstractScript.class), "setFilename", sig(void.class, String.class));
+ // ifnull ClassLoader
+ method.label(skip);
+
// instance config for the script run
method.newobj(p(RubyInstanceConfig.class));
method.dup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment