Skip to content

Fix Class.getMethod() to reject non-public interface methods - #23384

Merged
babsingh merged 1 commit into
eclipse-openj9:masterfrom
tomal-majumder:fix-getMethod-issue-22448
Mar 6, 2026
Merged

Fix Class.getMethod() to reject non-public interface methods#23384
babsingh merged 1 commit into
eclipse-openj9:masterfrom
tomal-majumder:fix-getMethod-issue-22448

Conversation

@tomal-majumder

@tomal-majumder tomal-majumder commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Fix Class.getMethod() to throw NoSuchMethodException for non-public interface methods

Problem

Class.getMethod() must return only public methods or throw NoSuchMethodException as per Java specification. Previously, when invoked on interface types with non-public methods (private static or non-static), the method incorrectly returned null instead of throwing the required exception.

Root Cause

The issue was in the initialResultShouldBeReplaced code path in getMethodHelper(). When publicOnly was true but the initial result was a non-public method, and no public alternatives were found, the method returned null instead of calling throwExceptionOrReturnNull().

Test cases added in Java9andUp/GetMethodTests covering cases of Class.getMethod() call for both public and non-public interface methods.

Test Results:

Local builds and Jenkins grinder tests were executed for aarch64 using JDK 11 and JDK 25.

  • sanity.functional – PASS and stable
  • extended.openjdk – PASS and stable
  • sanity.openjdk – JDK11: fails on jdk_lang_j9_0 and jdk_lang_j9_1. JDK25 fails on java/util/StringJoiner/StringJoinerTest

The sanity.openjdk failures are already tracked issues:

These failures are outside this change and appear to be existing issues.

Fixes: #22448

@tomal-majumder
tomal-majumder force-pushed the fix-getMethod-issue-22448 branch from bc81b56 to a9b77e9 Compare February 20, 2026 23:28
Comment thread jcl/src/java.base/share/classes/java/lang/Class.java Outdated
@babsingh

Copy link
Copy Markdown
Contributor

Also, the commit guidelines are not followed: https://github.com/eclipse-openj9/openj9/blob/master/CONTRIBUTING.md#commit-guidelines -> The body should be wrapped at 72 characters.

@tomal-majumder
tomal-majumder force-pushed the fix-getMethod-issue-22448 branch 3 times, most recently from d323ab2 to 39ac334 Compare February 27, 2026 01:11
Comment thread jcl/src/java.base/share/classes/java/lang/Class.java
Comment thread test/functional/Java9andUp/src/org/openj9/test/reflect/GetMethodTests.java Outdated
Comment thread test/functional/Java9andUp/src/org/openj9/test/reflect/GetMethodTests.java Outdated
@tomal-majumder
tomal-majumder force-pushed the fix-getMethod-issue-22448 branch from 39ac334 to fc97f64 Compare February 27, 2026 23:22
Comment thread test/functional/Java9andUp/src/org/openj9/test/reflect/GetMethodTests.java Outdated
@babsingh

babsingh commented Mar 2, 2026

Copy link
Copy Markdown
Contributor
  • Click "Resolve Conversation" for the feedback items that have already been addressed so the comments are collapsed.
  • Once you have addressed the remaining feedback regarding test stabilization, run and verify the changes using a personal build.
  • When everything is validated and ready for merge, set the PR status to "Ready to review".

@tomal-majumder
tomal-majumder force-pushed the fix-getMethod-issue-22448 branch 3 times, most recently from e302ec4 to 616ee59 Compare March 5, 2026 22:57
@tomal-majumder
tomal-majumder marked this pull request as ready for review March 5, 2026 23:14
@tomal-majumder
tomal-majumder requested a review from babsingh March 5, 2026 23:15
@tomal-majumder tomal-majumder changed the title WIP: Fix Class.getMethod() to reject non-public interface methods Fix Class.getMethod() to reject non-public interface methods Mar 5, 2026
@babsingh

babsingh commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test sanity amac jdk21

@babsingh

babsingh commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test sanity alinux64 jdk11

Comment thread test/functional/Java9andUp/src/org/openj9/test/reflect/GetMethodTests.java Outdated
Comment thread test/functional/Java9andUp/testng.xml
@babsingh

babsingh commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Documenting PR build links so only minimal testing is required for the requested formatting changes:

@tomal-majumder
tomal-majumder force-pushed the fix-getMethod-issue-22448 branch from 616ee59 to ea89a02 Compare March 6, 2026 18:48
Update getMethodHelper() to properly throw NoSuchMethodException
when Class.getMethod() is called on non-public interface methods.

Added test coverage in Java9andUp/GetMethodTests:
- Private static methods in interfaces throw NoSuchMethodException
- Private non-static methods in interfaces throw NoSuchMethodException
- Public methods successfully returns a Method

Fixes: eclipse-openj9#22448
Signed-off-by: Tomal Majumder <Tomal.Majumder@ibm.com>
@tomal-majumder
tomal-majumder force-pushed the fix-getMethod-issue-22448 branch from ea89a02 to 542e5da Compare March 6, 2026 18:53
@babsingh

babsingh commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

jenkins test sanity.functional amac jdk17

@babsingh
babsingh merged commit fa1b646 into eclipse-openj9:master Mar 6, 2026
6 checks passed
@tomal-majumder
tomal-majumder deleted the fix-getMethod-issue-22448 branch April 21, 2026 22:03
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.

Class.getMethod() incorrectly returns private static method in interface

3 participants