Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sealed classes #167

Closed
Ladicek opened this issue Jan 14, 2022 · 1 comment · Fixed by #348
Closed

Add support for sealed classes #167

Ladicek opened this issue Jan 14, 2022 · 1 comment · Fixed by #348
Assignees
Labels
serialization-format-change Changes that affect index serialization format
Milestone

Comments

@Ladicek
Copy link
Collaborator

Ladicek commented Jan 14, 2022

I'm not aware of any prospective user, so filing this just for tracking. I'm thinking 3.x only, unless someone actually asks for a backport to 2.x.

@Ladicek
Copy link
Collaborator Author

Ladicek commented Oct 13, 2023

Note to self: https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.31

We need to read (and remember) the PermittedSubclasses attribute in the ClassFile structure, which lists the permitted subclasses of the present class. Its presence also signifies that the present class is sealed.

/**
 * Returns the set of permitted subclasses of this {@code sealed} class (or interface).
 * Returns an empty set if this class is not {@code sealed}.
 *
 * @return immutable set of names of this class's permitted subclasses, never {@code null}
 */
public Set<DotName> permittedSubclasses() {
    ...
}

and a helper method

/**
 * @return {@code true} if this class object represents a sealed class (or interface)
 */
public boolean isSealed() {
    return !permittedSubclasses().isEmpty();
}

We don't need an isNonSealed() method, because we already have isFinal() and a permitted subclass of a sealed class must always be either sealed, non-sealed or final.

@Ladicek Ladicek added this to the 3.2.0 milestone Oct 13, 2023
@Ladicek Ladicek added the serialization-format-change Changes that affect index serialization format label Oct 13, 2023
@Ladicek Ladicek self-assigned this Oct 13, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
serialization-format-change Changes that affect index serialization format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant