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

JDK16: Class#permittedSubclasses() to return Class, not ClassDesc #10977

Closed
DanHeidinga opened this issue Oct 23, 2020 · 4 comments · Fixed by #11606
Closed

JDK16: Class#permittedSubclasses() to return Class, not ClassDesc #10977

DanHeidinga opened this issue Oct 23, 2020 · 4 comments · Fixed by #11606

Comments

@DanHeidinga
Copy link
Member

Based on recent Amber list update on Sealed Classes, expect an API change for JDK16:

Just to follow this up; we have decided to change the signature of permittedSubclasses to the following:

public Class<?>[] permittedSubclasses() {}

Still waiting on details of how to handle class loading errors, classes not yet loaded, etc.

@tajila
Copy link
Contributor

tajila commented Jan 5, 2021

@mikezhang1234567890 Can you please take a look at this

@tajila
Copy link
Contributor

tajila commented Jan 5, 2021

From the spec: http://cr.openjdk.java.net/~iris/se/16/build/latest/diffsFrom15%2b36/java.base/java/lang/Class.html

getPermittedSubclasses
 
public Class<?>[] getPermittedSubclasses() 
This method is associated with sealed classes , a preview feature of the Java language. Preview features may be removed in a future release, or upgraded to permanent features of the Java language.

Returns an array containing Class objects representing the direct subinterfaces or subclasses permitted to extend or implement this class or interface if it is sealed. The order of such elements is unspecified. The array is empty if this sealed class or interface has no permitted subclass. If this Class object represents a primitive type, void, an array type, or a class or interface that is not sealed, that is isSealed() returns false, then this method returns null. Conversely, if isSealed() returns true, then this method returns a non-null value. For each class or interface C which is recorded as a permitted direct subinterface or subclass of this class or interface, this method attempts to obtain the Class object for C (using the defining class loader of the current Class object). The Class objects which can be obtained and which are direct subinterfaces or subclasses of this class or interface, are indicated by elements of the returned array. If a Class object cannot be obtained, it is silently ignored, and not included in the result array.

Returns:
    an array of Class objects of the permitted subclasses of this class or interface, or null if this class or interface is not sealed. 
Throws:
    SecurityException - If a security manager, s, is present and the caller's class loader is not the same as or an ancestor of the class loader for that returned class and invocation of s.checkPackageAccess() denies access to the package of any class in the returned array. 
See Java Language Specification :
    8.1 Class Declarations
    9.1 Interface Declarations
Since:
    15 

Also note that the name of the function has changed.

We will need to create tests for this and verify the behaviour with the RI. I suspect the The Class objects which can be obtained wording implies that it only returns class objects for classes which are already loaded but this needs to be confirmed.

@mikezhang1234567890
Copy link
Contributor

Looking into it.

@andrew-m-leonard
Copy link
Contributor

fyi: adoptium/aqa-tests#2136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants