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

Problem accessing methods of package protected classes. #1444

Closed
AlBundy33 opened this issue Jan 26, 2014 · 2 comments
Closed

Problem accessing methods of package protected classes. #1444

AlBundy33 opened this issue Jan 26, 2014 · 2 comments

Comments

@AlBundy33
Copy link

See here: http://jira.codehaus.org/plugins/servlet/mobile#issue/JRUBY-6087

@AlBundy33
Copy link
Author

Copied from jira...

There is still a bug if classes are defined package-protected.
Here is my test-class (tested with Windows XP, RUBY_VERSION 1.9.3, JRUBY_VERSION 1.7.9, Java 1.7)

import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import org.testng.annotations.Test;

/**
 * Tests some problems with overloaded or added methods in extended, package-protected classes.
 * The tests will fail until the Impl-classes will be declared as public.
 */
@Test
public class JRuby6087Test
{
  public static interface MyInterface
  {
    void sayHello(String name);
  }

  static final class OverloadedImpl implements MyInterface
  {
    public void sayHello(String name)
    {
      System.out.println("hello " + name);
    }
    public void sayHello(String name, String surname)
    {
      System.out.println("hello " + name + " " + surname);
    }
  }

  static final class NewMethodImpl implements MyInterface
  {
    public void sayHello(String name)
    {
      System.out.println("hello " + name);
    }
    public void bye()
    {
      System.out.println("bye bye");
    }
  }

  public static class Provider
  {
    public MyInterface getOverloadedImpl()
    {
      return new OverloadedImpl();
    }
    public MyInterface getNewMethodImpl()
    {
      return new NewMethodImpl();
    }
  }

  public void testOverloadedMethod()
      throws Exception
  {
    System.out.println("JRuby6087Test.testOverloadedMethod()");
    final ScriptEngine e = new ScriptEngineManager().getEngineByName("ruby");
    e.getContext().setAttribute("o", new Provider(), ScriptContext.GLOBAL_SCOPE);

    final StringBuilder script = new StringBuilder();
    script.append("$o.overloadedImpl.sayHello('Al')\n");
    // reflection works
    script.append("$o.overloadedImpl.java_method('sayHello', [java.lang.String, java.lang.String]).call('this', 'works')\n");
    // normal call does not
    script.append("$o.overloadedImpl.sayHello('this', 'works not')\n");

    e.eval(script.toString());
  }

  public void testNewMethod()
      throws Exception
  {
    System.out.println("JRuby6087Test.testNewMethod()");
    final ScriptEngine e = new ScriptEngineManager().getEngineByName("ruby");
    e.getContext().setAttribute("o", new Provider(), ScriptContext.GLOBAL_SCOPE);

    final StringBuilder script = new StringBuilder();
    script.append("$o.newMethodImpl.sayHello('Al')\n");
    // reflection works
    script.append("$o.newMethodImpl.java_method('bye', []).call()\n");
    // normal call does not 
    script.append("$o.newMethodImpl.bye()\n");

    e.eval(script.toString());
  }
}

@kares
Copy link
Member

kares commented Jun 11, 2017

working fine on JRuby 9K (not sure about JRuby 1.7.x - which at this point isn't supported anyway)

JRuby6087Test.testOverloadedMethod()
hello Al
hello this works
hello this works not
JRuby6087Test.testNewMethod()
hello Al
bye bye
bye bye

@kares kares closed this as completed Jun 11, 2017
@kares kares added this to the Invalid or Duplicate milestone Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants