Skip to content

Fix: fields shadowing with sealed classes.#608

Open
Mo-Naga wants to merge 1 commit intojavapathfinder:java-17from
Mo-Naga:fix-sealed-classes
Open

Fix: fields shadowing with sealed classes.#608
Mo-Naga wants to merge 1 commit intojavapathfinder:java-17from
Mo-Naga:fix-sealed-classes

Conversation

@Mo-Naga
Copy link
Copy Markdown

@Mo-Naga Mo-Naga commented Mar 6, 2026

In issue #605, the JVMClassInfo has a shadowing fields: permittedSubclassNames, isSealed, that are exist in parent class ClassInfo. Removing this redefined field solves the problem.

Copilot AI review requested due to automatic review settings March 6, 2026 01:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes sealed class enforcement by removing JVMClassInfo field re-declarations that were shadowing ClassInfo’s isSealed and permittedSubclassNames, preventing ClassInfo.isSealed() / isPermittedSubclass() from observing parsed values.

Changes:

  • Removed permittedSubclassNames and isSealed field declarations from JVMClassInfo to avoid shadowing inherited ClassInfo state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 43 to 46
// To store partially resolved classes in setBootstrapMethod
protected static HashMap resolvedClasses = new HashMap<String, JVMClassInfo>();
protected ClassFile classFile;
protected String[] permittedSubclassNames;
protected boolean isSealed;

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

This change fixes sealed-class enforcement by removing field shadowing, but there’s still no regression test that would have caught the original bug (i.e., loading a class that illegally extends/implements a sealed type should fail). Please add a test that defines a sealed class/interface plus a non-permitted subclass/implementor and asserts JPF throws the expected IllegalAccessError (e.g., via verifyUnhandledException).

Copilot uses AI. Check for mistakes.
@Mahmoud-Khawaja
Copy link
Copy Markdown
Contributor

Hi Mo,
Thank you for your pull request. can you please add some tests? maybe something to test isSealed or isPermittedSubclass(). we need to check that parsing a .class file correctly populates isSealed and permittedSubclassNames. this is gonna be a little bit hard i know but i dont think there is a way to do it other than this.

@Mo-Naga
Copy link
Copy Markdown
Author

Mo-Naga commented Mar 9, 2026

Hi Mahmoud,

Thank you for your feedback. As far as I know, you don't need to test the pasting or the JPF behavior. I was thinking about adding a test in SealedClassesTest.java, similar to:

@Test
public void testSealedClassIsRecognized() {
    if (verifyNoPropertyViolation()) {
        assertTrue(Notification.class.isSealed());
        assertTrue(Payment.class.isSealed());
    }
}

However, it seems that is not going to work. I will continue working on this.

Thanks

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.

3 participants