Skip to content

Commit

Permalink
Fixes #3040. parameters on non-Ruby method with special arity will NPE
Browse files Browse the repository at this point in the history
Actually, I fixed this for all ASM-generated invokers.  We were using the named
versions of rest/opt instead of the anonymous versions.  Since native methods
have no names associated with the parameters I switched to anon versions.
enebo committed Jun 12, 2015
1 parent a57eba4 commit e1c0f7d
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
import org.jruby.exceptions.RaiseException;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.ArgumentType;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.Helpers;
@@ -702,27 +703,27 @@ public DescriptorInfo(List<JavaMethodDescriptor> descs) {
int i = 0;
for (; i < min; i++) {
if (i > 0) descBuilder.append(';');
descBuilder.append("q");
descBuilder.append(ArgumentType.REQ);
}
// variable arity
} else if (RICH_NATIVE_METHOD_PARAMETERS) {
int i = 0;
for (; i < min; i++) {
if (i > 0) descBuilder.append(';');
descBuilder.append("q");
descBuilder.append(ArgumentType.REQ);
}

for (; i < max; i++) {
if (i > 0) descBuilder.append(';');
descBuilder.append("o");
descBuilder.append(ArgumentType.ANONOPT);
}

if (rest) {
if (i > 0) descBuilder.append(';');
descBuilder.append("r");
descBuilder.append(ArgumentType.ANONREST);
}
} else {
descBuilder.append("r");
descBuilder.append(ArgumentType.ANONREST);
}

parameterDesc = descBuilder.toString();
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/runtime/ArgumentType.java
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ public enum ArgumentType {
anonrest("rest", "R", true),
anonkeyrest("keyrest", "N", true);

public static final String ANONOPT = anonopt.prefix;
public static final String ANONREST = anonrest.prefix;
public static final String REQ = req.prefix;

ArgumentType(String symbolicName, String prefix, boolean anonymous) {
this.symbolicName = symbolicName;
this.prefix = prefix;
7 changes: 7 additions & 0 deletions spec/regression/GH-3040_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rspec'

describe "A native method with no-simple arity should not NPE" do
it "an invoker has proper parameters" do
[].method(:shuffle).parameters.should eq([[:rest]])
end
end

0 comments on commit e1c0f7d

Please sign in to comment.