Skip to content

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

@dagrammy

Description

@dagrammy

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions