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

[GR-45258] MethodHandle on getter returns 0(false) instead of null for Long/Integer/Boolean using native-image #5672

Open
dagrammy opened this issue Dec 23, 2022 · 5 comments
Assignees

Comments

@dagrammy
Copy link

Describe the issue
Invoking a MethodHandle on a method with Long as return type returns 0 instead of null using native-image.

This can also be reproduced using Integer and Boolean as return type.

Steps to reproduce the issue
I added a reproducer, see https://github.com/dagrammy/graal-native-bug-test
git clone https://github.com/dagrammy/graal-native-bug-test.git and follow the steps in the readme https://github.com/dagrammy/graal-native-bug-test/blob/main/README.md

Describe GraalVM and your environment:

  • GraalVM version: graalvm-ce-java17-22.3.0
  • JDK major version: 17
  • OS: macOS Ventura 13.0.1
  • Architecture: arm/Apple M1

More details
Full example can be found here: https://github.com/dagrammy/graal-native-bug-test

This is a simple Pojo bean:

public class BeanLong {
  private Long value = null;

  public BeanLong() {
  }

  public Long getValue() {
    return value;
  }
}

The getter is invoked using a MethodHandle:

    Class<?> beanClass = BeanLong.class;
    Object bean = new BeanLong();

    Method method = beanClass.getMethod("getValue");
    MethodHandle methodHandle = MethodHandles.publicLookup().unreflect(method);

    // Call to MH returns 0 in native mode instead of null
    Long out = (Long) methodHandle.invoke(bean);
    System.out.println(">>>>> "   out   " <<<<<");

Output in JVM:

>>>>> null <<<<<

Output in native-image:

>>>>> 0 <<<<<

Using MethodHandles.publicLookup().findVirtual(beanClass, "getValue", MethodType.methodType(Long.class)); instead of unreflect also shows this behaviour (s. reproducer).

Maybe issue #5209 is related?

@hamburml
Copy link

hamburml commented Jan 3, 2023

@fniephaus @loicottet Happy new year :) I just wanted to ask if either one of you had time to check this issue. A short response is sufficient enough. Thx!

@loicottet
Copy link
Member

I haven't had a chance to look at it yet. At first glance this looks like an issue in the way our method handle implementation handles boxing of primitive return values rather than #5209 but I will need to look into it further to confirm.

@ygyg70
Copy link

ygyg70 commented Mar 30, 2023

I am seeing the same issue - would be great to see it fixed 👍

@fniephaus fniephaus changed the title MethodHandle on getter returns 0(false) instead of null for Long/Integer/Boolean using native-image [GR-45258] MethodHandle on getter returns 0(false) instead of null for Long/Integer/Boolean using native-image Mar 30, 2023
@dagrammy
Copy link
Author

Hello all,

is there any news on this topic?

The PR objectify/objectify#490 by @ygyg70 seems to fix the problem.
Would it be possible to merge the PR or are there concerns?

@ygyg70
Copy link

ygyg70 commented Jul 26, 2024

There are some discussions on the PR objectify/objectify#490

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

No branches or pull requests

4 participants