version is 1.6.7
The following class gives me an error when I try to load it, and I posit
that it shouldn’t:
package org.apache.pig.scripting.jruby;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
@JRubyClass(name=“ExampleA”)
public class RubyExampleA extends RubyObject {
private static final ObjectAllocator ALLOCATOR = new
ObjectAllocator() {
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new RubyExampleA(runtime, klass);
}
};
public static RubyClass define(Ruby runtime) {
RubyClass result =
runtime.defineClass(“ExampleA”,runtime.getObject(), ALLOCATOR);
result.kindOf = new RubyModule.KindOf() {
public boolean isKindOf(IRubyObject obj, RubyModule type) {
return obj instanceof RubyExampleA;
}
};
result.defineAnnotatedMethods(RubyExampleA.class);
return result;
}
public RubyExampleA(final Ruby ruby, RubyClass rc) {
super(ruby,rc);
}
@JRubyMethod
public IRubyObject initialize(ThreadContext context) {
return this;
}
@JRubyMethod
public static IRubyObject hey(ThreadContext context) {
System.out.println("hey");
return context.nil;
}
}
The error:
NativeException: java.lang.NegativeArraySizeException: null
from org/jruby/anno/JavaMethodDescriptor.java:77:in <init>' from org/jruby/RubyModule.java:591:in
clump’
from org/jruby/anno/TypePopulator.java:62:in populate' from org/jruby/RubyModule.java:685:in
defineAnnotatedMethodsIndividually’
from org/jruby/RubyModule.java:573:in defineAnnotatedMethods' from org/apache/pig/scripting/jruby/RubyExampleA.java:30:in
define’
from org/apache/pig/scripting/jruby/PigJrubyLibrary.java:18:in
load' from ./pigudf.rb:5:in
(root)’
Digging around a little but, in org/jruby/anno/JavaMethodDescriptor.java
I
see:
int start = (hasContext ? 1 : 0) + (isStatic ? 1 : 0);
int end = parameters.length - (hasBlock ? 1 : 0);
argumentTypes = new Class[end - start];
So in the case where it is static and has no arguments, you’re going to
have issues. I tried removing the static piece and adding an argument,
and
predictably, it was fine.
Would love to hear if this is expected, and what I should do to mitigate
it
if it is… and if it’s not, where I should file a bug report