Skip to content

[ji] should allow calling protected Java method with send #5310

Description

@kares

... works on Java 8 but not on 10(+)

jruby 9.2.1.0-SNAPSHOT (2.5.0) 2018-09-11 055a178 Java HotSpot(TM) 64-Bit Server VM 10.0.1+10 on 10.0.1+10 +jit [linux-x86_64]
irb(main):001:0> Java::JavaUtilLogging::StreamHandler.new.setOutputStream
Traceback (most recent call last):
        6: from /home/kares/workspace/oss/jruby/bin/jirb:13:in `<main>'
        5: from org/jruby/RubyKernel.java:1178:in `catch'
        4: from org/jruby/RubyKernel.java:1178:in `catch'
        3: from org/jruby/RubyKernel.java:1412:in `loop'
        2: from org/jruby/RubyKernel.java:1040:in `eval'
        1: from (irb):1:in `evaluate'
NoMethodError (undefined method `setOutputStream' for #<Java::JavaUtilLogging::StreamHandler:0x18a645fd>)
irb(main):002:0> Java::JavaUtilLogging::StreamHandler.new.send :setOutputStream, nil
Traceback (most recent call last):
        6: from /home/kares/workspace/oss/jruby/bin/jirb:13:in `<main>'
        5: from org/jruby/RubyKernel.java:1178:in `catch'
        4: from org/jruby/RubyKernel.java:1178:in `catch'
        3: from org/jruby/RubyKernel.java:1412:in `loop'
        2: from org/jruby/RubyKernel.java:1040:in `eval'
        1: from (irb):2:in `evaluate'
NoMethodError (undefined method `setOutputStream' for #<Java::JavaUtilLogging::StreamHandler:0x4650a407>)

the first failure is fine (although if it would be marked as a protected instance method the failure would be different), setOutputStream is a protected Java method, the second would be more Ruby if it worked ... this all works on Java 8 - would argue the direct call working is not something JRuby encouraged or specified, nevertheless the second from should work everywhere - seems like we can not set it accessible (due JDK modularization?).

extracted from: #4851 (comment)

related - similar accessibility issue on Java 10: #5284

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions