Skip to content

Add Java 11 Nestmate support to java.lang.Class model#580

Open
HritikRaj2 wants to merge 1 commit into
javapathfinder:masterfrom
HritikRaj2:add-nestmate-support
Open

Add Java 11 Nestmate support to java.lang.Class model#580
HritikRaj2 wants to merge 1 commit into
javapathfinder:masterfrom
HritikRaj2:add-nestmate-support

Conversation

@HritikRaj2
Copy link
Copy Markdown
Contributor

Summary

Implemented missing Java 11 Nestmate access control methods in the java.lang.Class model. This allows JPF to execute code that relies on getNestHost() and isNestmateOf(), which are increasingly common in modern Java libraries.

Changes

  • Modified: src/classes/modules/java.base/java/lang/Class.java
    • Added getNestHost(): Traversing getEnclosingClass() to find the nest host (top-level class).
    • Added isNestmateOf(Class): Compares nest hosts of two classes.
  • Added: src/tests/gov/nasa/jpf/test/java/lang/NestmateTest.java
    • Verified behavior for Top-Level classes (host is self).
    • Verified behavior for Inner classes (host is enclosing class).

Testing

  • NestmateTest.java passes
  • Full build successful.

Relation to Issues

Partial fix for general "Missing Methods in Class" issues (like #235), specifically targeting Java 11 support.

@HritikRaj2
Copy link
Copy Markdown
Contributor Author

Hi @cyrille-artho, following your advice to focus on functionality rather than test optimization, I've submitted a PR adding Java 11 Nestmate support (getNestHost, isNestmateOf) to the Class model.

I included a new unit test to verify the behavior for both top-level and inner classes. Ready for your review!

Copy link
Copy Markdown
Member

@cyrille-artho cyrille-artho left a comment

Choose a reason for hiding this comment

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

Thank you for this addition. The implementation looks correct, and a few more tests against unusual cases can ascertain that.
Please remove the extensive formatting changes at the beginning, as this increases the size of the patch and may make it hard to merge to other branches later.

* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.
* * http://www.apache.org/licenses/LICENSE-2.0.
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.

Please try not to reformat existing code/comments, as this can make it harder to merge your patch into other branches later.

public class Inner {}

@Test
public void testNestHost() {
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.

Looks good. Please also add a test for some other cases: "If this Class object represents a primitive type, an array type, or void, then this method returns this".

@HritikRaj2
Copy link
Copy Markdown
Contributor Author

Thanks for the review, @cyrille-artho! I have reverted the formatting changes to the license header to keep the diff clean. I also added the requested test cases for primitives, arrays, and void in NestmateTest.java. Ready for another look!

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.

2 participants