Skip to content

Commit

Permalink
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ public class ArgumentDescriptor {
public static final ArgumentDescriptor[] EMPTY_ARRAY = new ArgumentDescriptor[0];

public ArgumentDescriptor(ArgumentType type, String name) {
assert name != null || type.anonymous : "null argument name given for non-anonymous argument type";
this.type = type;
this.name = name;
}
13 changes: 12 additions & 1 deletion core/src/main/java/org/jruby/runtime/ArgumentType.java
Original file line number Diff line number Diff line change
@@ -52,7 +52,18 @@ public String renderPrefixForm(String name) {
}

public RubyArray toArrayForm(Ruby runtime, String name) {
return anonymous ? runtime.newArray(runtime.newSymbol(symbolicName)) : runtime.newArray(runtime.newSymbol(symbolicName), runtime.newSymbol(name));
// we check for null name here as a precaution, since it will certainly blow up newSymbol (#3086)
return anonymous || name == null ? runtime.newArray(runtime.newSymbol(symbolicName)) : runtime.newArray(runtime.newSymbol(symbolicName), runtime.newSymbol(name));
}

public ArgumentType anonymousForm() {
switch (this) {
case opt: return anonopt;
case req: return anonreq;
case rest: return anonrest;
case keyrest: return anonkeyrest;
}
return this;
}

public final String symbolicName;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -2393,7 +2393,7 @@ public static ArgumentDescriptor[] parameterListToArgumentDescriptors(String[] p
if (param.length() > 1) {
parms[i] = new ArgumentDescriptor(type, param.substring(1));
} else {
parms[i] = new ArgumentDescriptor(type);
parms[i] = new ArgumentDescriptor(type.anonymousForm());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe 'A method with anonymous required arguments' do
it 'can to_proc and produce parameters without error' do
# anonymous required args built wrong, caused NPE (#3086)
method(:`).to_proc.parameters.should == [[:req]]
end
end

0 comments on commit 5e4d2f8

Please sign in to comment.