Interesting Java integration phenomenon

View: New views
3 Messages — Rating Filter:   Alert me  

Interesting Java integration phenomenon

by Trejkaz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

While I was constructing a test case to try and reproduce another
problem (which turned out to be fixed) I encountered something rather
interesting.

    shard:jruby trejkaz$ cat A.java
    public class A {
        public String getPublic() {
            return "public";
        }
        public String getPublic1() {
            return "public";
        }
    }
    shard:jruby trejkaz$ javac A.java
    shard:jruby trejkaz$ jar cf a.jar A.class
    shard:jruby trejkaz$ java -jar jruby-complete-1.4.0RC3.jar -S irb
    irb(main):001:0> require 'a.jar'
    => true
    irb(main):002:0> include_class 'A'
    => ["A"]
    irb(main):003:0> a = A.new
    => #<Java::Default::A:0x39060b>
    irb(main):004:0> a.public
    NoMethodError: undefined method `public' for #<Java::Default::A:0x39060b>
    from (irb):5
    irb(main):005:0> a.public1
    => "public"
    irb(main):006:0>

From the outside it's not obvious why 'public' would be special like
this, it just happened to be the first name I choose for the method I
was testing at the time.  Ruby objects don't have anything special
called 'public' and neither do Java objects, which is why this seemed
interesting to me.

TX

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Interesting Java integration phenomenon

by Thomas E Enebo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well had it been a static method I think the answer would have been
that 'public' is a method on Module.  Since this is calling on an
instance method, I am guessing maybe 'public' is in RESERVED_NAMES
when it should be in STATIC_RESERVED_WORDS.  Can you file a bug on
this?

The background is that for a small set of important Ruby methods we
will not override their definition in case of conflict.  'public' is
in this list.

As a workaround you can use 'java_send' to still call the method...

-Tom


On Sat, Oct 31, 2009 at 10:41 PM, Trejkaz <trejkaz@...> wrote:

> While I was constructing a test case to try and reproduce another
> problem (which turned out to be fixed) I encountered something rather
> interesting.
>
>    shard:jruby trejkaz$ cat A.java
>    public class A {
>        public String getPublic() {
>            return "public";
>        }
>        public String getPublic1() {
>            return "public";
>        }
>    }
>    shard:jruby trejkaz$ javac A.java
>    shard:jruby trejkaz$ jar cf a.jar A.class
>    shard:jruby trejkaz$ java -jar jruby-complete-1.4.0RC3.jar -S irb
>    irb(main):001:0> require 'a.jar'
>    => true
>    irb(main):002:0> include_class 'A'
>    => ["A"]
>    irb(main):003:0> a = A.new
>    => #<Java::Default::A:0x39060b>
>    irb(main):004:0> a.public
>    NoMethodError: undefined method `public' for #<Java::Default::A:0x39060b>
>        from (irb):5
>    irb(main):005:0> a.public1
>    => "public"
>    irb(main):006:0>
>
> From the outside it's not obvious why 'public' would be special like
> this, it just happened to be the first name I choose for the method I
> was testing at the time.  Ruby objects don't have anything special
> called 'public' and neither do Java objects, which is why this seemed
> interesting to me.
>
> TX
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>



--
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.enebo@...

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Interesting Java integration phenomenon

by Trejkaz-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Nov 2, 2009 at 2:52 AM, Thomas E Enebo <tom.enebo@...> wrote:
> Well had it been a static method I think the answer would have been
> that 'public' is a method on Module.  Since this is calling on an
> instance method, I am guessing maybe 'public' is in RESERVED_NAMES
> when it should be in STATIC_RESERVED_WORDS.  Can you file a bug on
> this?

Filed: http://jira.codehaus.org/browse/JRUBY-4198

> The background is that for a small set of important Ruby methods we
> will not override their definition in case of conflict.  'public' is
> in this list.
>
> As a workaround you can use 'java_send' to still call the method...

For our real system, we are deliberately trying to avoid using names
which are generic enough to cause conflicts (both in JRuby and --
hopefully -- in whatever other scripting languages users might use.)
I found this purely by chance and thought it was interesting.

TX

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email