Fix: fields shadowing with sealed classes.#608
Fix: fields shadowing with sealed classes.#608Mo-Naga wants to merge 1 commit intojavapathfinder:java-17from
Conversation
There was a problem hiding this comment.
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
permittedSubclassNamesandisSealedfield declarations fromJVMClassInfoto avoid shadowing inheritedClassInfostate.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // To store partially resolved classes in setBootstrapMethod | ||
| protected static HashMap resolvedClasses = new HashMap<String, JVMClassInfo>(); | ||
| protected ClassFile classFile; | ||
| protected String[] permittedSubclassNames; | ||
| protected boolean isSealed; | ||
|
|
There was a problem hiding this comment.
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).
|
Hi Mo, |
|
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 |
In issue #605, the
JVMClassInfohas a shadowing fields:permittedSubclassNames,isSealed, that are exist in parent classClassInfo. Removing this redefined field solves the problem.