Skip to content

Method aliases are not consistently mapped for a class with isFoo and getFoo #3470

@benissimo

Description

@benissimo

For a class

public class Ugh {

  public boolean isFoo() {
     return false;
  }

  public int getFoo() {
     return 3;
  }
}

calling .foo from Jruby results in inconsistent behavior.

Sometimes it behaves this way:

jruby-1.7.22 :001 > Java::Ugh.new.foo
 => 3 

Other times (exit jruby and fire up irb a new time, this time using, say, java 8 instead of java 7) it behaves this way:

jruby-1.7.22 :001 > Java::Ugh.new.foo
 => false 

Per https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
'something' -> 'getSomething'
'something?' -> 'isSomething'

However in practice 'something' gets mapped to both 'getSomething' and 'isSomething' (assuming the java class has both methods) and, as the order those methods get mapped appears to be nondeterministic, there's no consistency as to which one gets mapped last (clobbering the first). At least that's my best guess as to what's causing the issue here.

We stumbled across this when upgrading to java 8, initially thought it was related to that, but ultimately found there to be no consistent behavior (different developers got different results running the above test).

We suspect that ./core/src/main/java/org/jruby/javasupport/JavaUtil.java is involved.

Suggestion: do not map 'foo' to 'isFoo'. Only map 'foo?' to 'isFoo' (as the wiki says).
Or: ensure java methods are sorted in some consistent order before mapping them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions