Skip to content

# Fix #629: Incorrect method reference results when return value requires boxing - #630

Open
alwaysalearner1234 wants to merge 2 commits into
javapathfinder:masterfrom
alwaysalearner1234:master
Open

# Fix #629: Incorrect method reference results when return value requires boxing#630
alwaysalearner1234 wants to merge 2 commits into
javapathfinder:masterfrom
alwaysalearner1234:master

Conversation

@alwaysalearner1234

Copy link
Copy Markdown

Description

Fixes #629.

Method references that return a primitive value were returning incorrect values when the functional interface expected an object.

For example:

Function<String, Integer> f = String::length;

The primitive int result was not being boxed before being returned as an object.

Fix

  • Detect primitive-to-reference return type conversions.
  • Box primitive values using the appropriate wrapper valueOf() method.
  • Keep existing primitive and reference return behavior unchanged.

Example

Before:

Function<String, Integer> f = String::length;
→ incorrect value

After:

Function<String, Integer> f = String::length;
→ 5

Testing

Tested with method references including:

  • String::length
  • String::isEmpty
  • Integer::parseInt
  • Bound instance methods returning primitives
  • ToIntFunction<String> to ensure existing behavior still works

@cyrille-artho

cyrille-artho commented Aug 11, 2026

Copy link
Copy Markdown
Member

On my Mac laptop with OpenJDK 11.0.32, 20 unit tests fail.
The result is the same for the current version of jpf-core, branch master, in the main repository.
On Darshan's system (OpenJDK 11.0.31 on IntelliJ on Windows), all unit tests pass.

@alwaysalearner1234

Copy link
Copy Markdown
Author

Thanks for taking the time to test this and verify the behavior on your end!

I investigated the test failures locally and compared the PR branch against a clean checkout of upstream/master. The failures are also reproducible on the current master branch, so they do not appear to be introduced by the changes in this PR.

The failures seem to be environment-specific, particularly given the difference between the macOS/OpenJDK 11.0.32 and Windows/OpenJDK 11.0.31 environments.

For this PR, I focused on the method-reference boxing issue described in #629 and verified that the relevant regression cases behave correctly after the change.

I'll keep the PR focused on #629 and leave the pre-existing test failures as a separate issue.

@cyrille-artho cyrille-artho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two unit tests fail.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Method references return wrong values when the result needs boxing

2 participants