#618 Ambiguous method call on java object

Yelagin Mon 1 Jun 2009

Toolkit.getDefaultToolkit()->disableBackgroundErase(myCanvas)

results in this: sys::Err: Cannot call [java]sun.awt::SunToolkit.disableBackgroundErase: sys::A rgErr: Ambiguous method call disableBackgroundErase

What's the problem?

brian Mon 1 Jun 2009

Typically that error indicates trying to call a method and it can't figure out which overloaded version you are calling.

I am not familiar with SunToolkit.disableBackgroundErase, but googling around it doesn't appear to be an overloaded method is it? If it isn't, then likely it is a bug in the Java FFI resolver - I can take a look tonight.

Hard to tell what could be going on without adding some debug - here the source code where the error is reported.

brian Mon 1 Jun 2009

@Yelagin

OK, my original comment was incorrect - this is a problem with the runtime dispatch of the dynamic invoke operator (not a compiler error). That code is in JavaType.java.

I tried to reproduce this problem using this program:

using [java]java.awt
class Foo {
  static Void main() {
    myCanvas := Canvas()
    frame := Frame() { add(myCanvas); setVisible(true) }
    Toolkit.getDefaultToolkit()->disableBackgroundErase(myCanvas)
  }
}

But I cannot duplicate the problem.

What version of Java are you using?

Yelagin Tue 2 Jun 2009

On jre 1.6.0_13-b03 and jre 1.6.0_14-b08 your code throws the same exception.

C:\work>fan test.fan
sys::Err: Cannot call '[java]sun.awt::SunToolkit.disableBackgroundErase': sys::ArgErr: Ambiguous method call 'disableBackgroundErase'
fan.sys.Method.invoke (Method.java:569)
fan.sys.Method$MethodFunc.callOn (Method.java:217)
fan.sys.FanObj.doTrap (FanObj.java:145)
fan.sys.FanObj.trap (FanObj.java:133)
test_0::Foo.main (/C:/work/test.fan:6)
sun.reflect.NativeMethodAccessorImpl.invoke0 (Unknown)
sun.reflect.NativeMethodAccessorImpl.invoke (Unknown)
sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown)
java.lang.reflect.Method.invoke (Unknown)
fan.sys.Method.invoke (Method.java:539)
fan.sys.Method$MethodFunc.callList (Method.java:185)
fan.sys.Method.callList (Method.java:147)
fanx.tools.Fan.callMain (Fan.java:136)
fanx.tools.Fan.executeFile (Fan.java:89)
fanx.tools.Fan.execute (Fan.java:35)
fanx.tools.Fan.run (Fan.java:229)
fanx.tools.Fan.main (Fan.java:267)

brian Tue 2 Jun 2009

Promoted to ticket #618 and assigned to brian

OK, I upgraded my JRE and I can see the problem now:

public void sun.awt.SunToolkit.disableBackgroundErase(java.awt.Canvas)
public void sun.awt.SunToolkit.disableBackgroundErase(java.awt.Component)

I haven't fully implemented the JLS rules for resolving the best match yet, so that is the problem.

I will try to push a fix to hg Wed morning.

In the meantime here a work around using old-school Java reflection:

t := Toolkit.getDefaultToolkit
m := t.getClass.getMethod("disableBackgroundErase", 
                          [Class.forName("java.awt.Canvas")])
m.invoke(t, [myCanvas])

brian Tue 2 Jun 2009

Ticket resolved in 1.0.44

Fix pushed to hg

Login or Signup to reply.