Skip to content

Instantly share code, notes, and snippets.

@headius
Last active May 7, 2024 22:39
Show Gist options
  • Save headius/c3b01570397f9202999eac2ddaf9cdef to your computer and use it in GitHub Desktop.
Save headius/c3b01570397f9202999eac2ddaf9cdef to your computer and use it in GitHub Desktop.
Fix for jruby/jruby#8178 by only allowing a RubyArray into Argv
diff --git a/core/src/main/java/org/jruby/embed/variable/AbstractVariable.java b/core/src/main/java/org/jruby/embed/variable/AbstractVariable.java
index 46177487d7..85ede943b4 100644
--- a/core/src/main/java/org/jruby/embed/variable/AbstractVariable.java
+++ b/core/src/main/java/org/jruby/embed/variable/AbstractVariable.java
@@ -104,8 +104,15 @@ abstract class AbstractVariable implements BiVariable {
} else {
javaType = javaObject.getClass();
}
+
+ updateRubyObjectFromJavaObject(runtime);
+ }
+
+ protected IRubyObject updateRubyObjectFromJavaObject(final Ruby runtime) {
rubyObject = JavaEmbedUtils.javaToRuby(runtime, javaObject);
fromRuby = false;
+
+ return rubyObject;
}
protected void updateRubyObject(final IRubyObject rubyObject) {
diff --git a/core/src/main/java/org/jruby/embed/variable/Argv.java b/core/src/main/java/org/jruby/embed/variable/Argv.java
index ad8559f10c..d35c20769b 100644
--- a/core/src/main/java/org/jruby/embed/variable/Argv.java
+++ b/core/src/main/java/org/jruby/embed/variable/Argv.java
@@ -38,6 +38,7 @@ import org.jruby.RubyModule;
import org.jruby.RubyNil;
import org.jruby.RubyObject;
import org.jruby.embed.internal.BiVariableMap;
+import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.runtime.builtin.IRubyObject;
/**
@@ -117,14 +118,7 @@ public class Argv extends AbstractVariable {
public void inject() {
final Ruby runtime = getRuntime();
- final RubyArray argv = RubyArray.newArray(runtime);
- if ( javaObject instanceof Collection ) {
- argv.addAll( (Collection) javaObject );
- }
- else if ( javaObject instanceof String[] ) {
- for ( String str : (String[]) javaObject ) argv.add(str);
- }
- this.rubyObject = argv; fromRuby = true;
+ IRubyObject argv = updateRubyObjectFromJavaObject(runtime);
RubyModule rubyModule = getRubyClass(runtime);
// SSS FIXME: With rubyclass stack gone, this needs a replacement
@@ -136,6 +130,20 @@ public class Argv extends AbstractVariable {
runtime.getConstantInvalidator(name).invalidate();
}
+ protected IRubyObject updateRubyObjectFromJavaObject(final Ruby runtime) {
+ final RubyArray argv = RubyArray.newArray(runtime);
+ if ( javaObject instanceof Collection) {
+ argv.addAll( (Collection) javaObject );
+ }
+ else if ( javaObject instanceof String[] ) {
+ for ( String str : (String[]) javaObject ) argv.add(str);
+ }
+ this.rubyObject = argv;
+ this.fromRuby = true;
+
+ return argv;
+ }
+
/**
* Removes this object from {@link BiVariableMap}. Also, initialize
* this variable in top self.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment