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

Reflect.callMethod() crashes on Java when defaulting arguments #8975

Closed
ckentgeorge opened this issue Nov 17, 2019 · 5 comments
Closed

Reflect.callMethod() crashes on Java when defaulting arguments #8975

ckentgeorge opened this issue Nov 17, 2019 · 5 comments

Comments

@ckentgeorge
Copy link

@ckentgeorge ckentgeorge commented Nov 17, 2019

Running Haxe 4.0.2 and hxjava 3.2.0, the following code crashes when attempting Reflect.callMethod() with Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1.

Here's the a simplified example that crashes:

class Remote
{
   public function new() {}

   public function doIt
   (
      prefix:String, 
      suffix:String = "bet"
   )
   {
      return prefix + suffix;
   }
}

#if !macro
class Main
{
   private static function main():Void
   {
      var remote = new Remote();

      // This works.
      trace(remote.doIt("Alpha"));
      
      // This doesn't when targetting Java.
      trace(
         Reflect.callMethod(
            remote,
            remote.doIt,
            ["Alpha"]
         )
      );
   }
}
#end
@RealyUniqueName

This comment has been minimized.

Copy link
Member

@RealyUniqueName RealyUniqueName commented Nov 18, 2019

I think similar remark should be added to Reflect.callMethod doc (from Type.createInstance()):

if the number of elements in args does not match the expected number of constructor arguments, or if any argument has an invalid type, or if cl has no own constructor, the result is unspecified.

In particular, default values of constructor arguments are not guaranteed to be taken into account.
@ncannasse

This comment has been minimized.

Copy link
Member

@ncannasse ncannasse commented Nov 18, 2019

Regarding optional arguments / default values support, which platforms are concerned with this limitation ? If it's only Java maybe something should be done for this platform.

@ckentgeorge

This comment has been minimized.

Copy link
Author

@ckentgeorge ckentgeorge commented Nov 18, 2019

This worked just fine in Haxe 3. We're in a tough spot if support for this is intentionally dropped for Haxe 4. For example, Haxe script becomes fairly less usable when targeting Java.

@RealyUniqueName

This comment has been minimized.

Copy link
Member

@RealyUniqueName RealyUniqueName commented Nov 18, 2019

If it was working in Haxe 3, then it's a regression of Haxe 4 and should be fixed in 4.0.3

@RealyUniqueName

This comment has been minimized.

Copy link
Member

@RealyUniqueName RealyUniqueName commented Nov 23, 2019

Waiting for CI before merging into 4.0_bugfix branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.