Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException raises when Combining specific args with required #1692

Closed
taichi opened this issue May 13, 2014 · 1 comment

Comments

@taichi
Copy link
Contributor

taichi commented May 13, 2014

ArrayIndexOutOfBoundsException raises when Combining specific args with required.

i use

  • jruby-complete-1.7.12
  • JDK1.7.0_21 or JDK1.8.0

code is

import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.builtin.IRubyObject;

public class Bug extends RubyObject {

    public Bug(Ruby r, RubyClass rc) {
        super(r, rc);
    }

    @JRubyMethod(required=1)
    public void test(IRubyObject a, IRubyObject[] args) {}

    public static void main(String[] args) {
        Ruby r =JavaEmbedUtils.initialize(new java.util.ArrayList<>());
        r.defineClass("Bug", r.getObject(), new ObjectAllocator() {
            @Override
            public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
                return new Bug(runtime, klazz);
            }
        }).defineAnnotatedMethods(Bug.class);
    }
}

this code happen to ArrayIndexOutOfBoundsException

java.lang.ArrayIndexOutOfBoundsException: -1
    at org.jruby.org.objectweb.asm.Frame.a(Unknown Source)
    at org.jruby.org.objectweb.asm.Frame.a(Unknown Source)
    at org.jruby.org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
    at org.jruby.compiler.impl.SkinnyMethodAdapter.end(SkinnyMethodAdapter.java:563)
    at org.jruby.compiler.impl.SkinnyMethodAdapter.end(SkinnyMethodAdapter.java:540)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.addAnnotatedMethodInvoker(InvocationMethodFactory.java:1529)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.getAnnotatedMethodClass(InvocationMethodFactory.java:845)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.getAnnotatedMethod(InvocationMethodFactory.java:894)
    at org.jruby.RubyModule.defineAnnotatedMethod(RubyModule.java:805)
    at org.jruby.RubyModule.defineAnnotatedMethod(RubyModule.java:768)
    at org.jruby.anno.TypePopulator$DefaultTypePopulator.populate(TypePopulator.java:103)
    at org.jruby.RubyModule.defineAnnotatedMethodsIndividually(RubyModule.java:762)
    at org.jruby.RubyModule.defineAnnotatedMethods(RubyModule.java:633)
    at Bug.main(Bug.java:20)
Exception in thread "main" org.jruby.exceptions.RaiseException: (LoadError) -1
@kares
Copy link
Member

kares commented Mar 19, 2015

this is actually how the extension API works (even in 9K) - you get all of the arguments in a single [array] when it's part of the method signature ... but you can use over-loads to handle cases based on argument count ... if that helps

@kares kares closed this as completed Mar 19, 2015
@enebo enebo added this to the Invalid or Duplicate milestone Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants