Skip to content

Commit 379376f

Browse files
Gavin BiermanVicente Romero
Gavin Bierman
authored and
Vicente Romero
committedJun 2, 2021
8265130: Make ConstantDesc class hierarchy sealed
Reviewed-by: mchung, jvernee, vromero
1 parent 00c7aee commit 379376f

File tree

6 files changed

+25
-38
lines changed

6 files changed

+25
-38
lines changed
 

‎src/java.base/share/classes/java/lang/constant/ClassDesc.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,15 @@
4949
* {@linkplain ClassDesc} for the component type and then call the {@link #arrayType()}
5050
* or {@link #arrayType(int)} methods.
5151
*
52-
* @apiNote In the future, if the Java language permits, {@linkplain ClassDesc}
53-
* may become a {@code sealed} interface, which would prohibit subclassing except
54-
* by explicitly permitted types. Non-platform classes should not implement
55-
* {@linkplain ClassDesc} directly.
56-
*
5752
* @see ConstantDescs
5853
*
5954
* @since 12
6055
*/
61-
public interface ClassDesc
56+
public sealed interface ClassDesc
6257
extends ConstantDesc,
63-
TypeDescriptor.OfField<ClassDesc> {
58+
TypeDescriptor.OfField<ClassDesc>
59+
permits PrimitiveClassDescImpl,
60+
ReferenceClassDescImpl {
6461

6562
/**
6663
* Returns a {@linkplain ClassDesc} for a class or interface type,

‎src/java.base/share/classes/java/lang/constant/ConstantDesc.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@
6868
* {@link Object#equals(Object)} method. There is no guarantee that any
6969
* particular entity will always be represented by the same descriptor instance.
7070
*
71-
* @apiNote In the future, if the Java language permits, {@linkplain ConstantDesc}
72-
* may become a {@code sealed} interface, which would prohibit subclassing except by
73-
* explicitly permitted types. Clients can assume that the following
74-
* set of subtypes is exhaustive: {@link String}, {@link Integer},
75-
* {@link Long}, {@link Float}, {@link Double}, {@link ClassDesc},
76-
* {@link MethodTypeDesc}, {@link MethodHandleDesc}, and
77-
* {@link DynamicConstantDesc}; this list may be extended to reflect future
78-
* changes to the constant pool format as defined in JVMS 4.4.
79-
*
8071
* @see Constable
8172
* @see ConstantDescs
8273
*
8374
* @jvms 4.4 The Constant Pool
8475
*
8576
* @since 12
8677
*/
87-
public interface ConstantDesc {
78+
public sealed interface ConstantDesc
79+
permits ClassDesc,
80+
MethodHandleDesc,
81+
MethodTypeDesc,
82+
Double,
83+
DynamicConstantDesc,
84+
Float,
85+
Integer,
86+
Long,
87+
String {
8888
/**
8989
* Resolves this descriptor reflectively, emulating the resolution behavior
9090
* of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution

‎src/java.base/share/classes/java/lang/constant/DirectMethodHandleDesc.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@
4646
* {@link MethodHandle}. A {@linkplain DirectMethodHandleDesc} corresponds to
4747
* a {@code Constant_MethodHandle_info} entry in the constant pool of a classfile.
4848
*
49-
* @apiNote In the future, if the Java language permits, {@linkplain DirectMethodHandleDesc}
50-
* may become a {@code sealed} interface, which would prohibit subclassing except
51-
* by explicitly permitted types. Non-platform classes should not implement
52-
* {@linkplain DirectMethodHandleDesc} directly.
53-
*
5449
* @since 12
5550
*/
56-
public interface DirectMethodHandleDesc extends MethodHandleDesc {
51+
public sealed interface DirectMethodHandleDesc
52+
extends MethodHandleDesc
53+
permits DirectMethodHandleDescImpl {
5754
/**
5855
* Kinds of method handles that can be described with {@linkplain DirectMethodHandleDesc}.
5956
*

‎src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*
5757
* @since 12
5858
*/
59-
public abstract class DynamicConstantDesc<T>
59+
public abstract non-sealed class DynamicConstantDesc<T>
6060
implements ConstantDesc {
6161

6262
private final DirectMethodHandleDesc bootstrapMethod;

‎src/java.base/share/classes/java/lang/constant/MethodHandleDesc.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@
3535
* A <a href="package-summary.html#nominal">nominal descriptor</a> for a
3636
* {@link MethodHandle} constant.
3737
*
38-
* @apiNote In the future, if the Java language permits, {@linkplain MethodHandleDesc}
39-
* may become a {@code sealed} interface, which would prohibit subclassing except
40-
* by explicitly permitted types. Non-platform classes should not implement
41-
* {@linkplain MethodHandleDesc} directly.
42-
*
4338
* @since 12
4439
*/
45-
public interface MethodHandleDesc
46-
extends ConstantDesc {
40+
public sealed interface MethodHandleDesc
41+
extends ConstantDesc
42+
permits AsTypeMethodHandleDesc,
43+
DirectMethodHandleDesc {
4744

4845
/**
4946
* Creates a {@linkplain MethodHandleDesc} corresponding to an invocation of a

‎src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@
3434
* A <a href="package-summary.html#nominal">nominal descriptor</a> for a
3535
* {@linkplain MethodType} constant.
3636
*
37-
* @apiNote In the future, if the Java language permits, {@linkplain MethodTypeDesc}
38-
* may become a {@code sealed} interface, which would prohibit subclassing except
39-
* by explicitly permitted types. Non-platform classes should not implement
40-
* {@linkplain MethodTypeDesc} directly.
41-
*
4237
* @since 12
4338
*/
44-
public interface MethodTypeDesc
39+
public sealed interface MethodTypeDesc
4540
extends ConstantDesc,
46-
TypeDescriptor.OfMethod<ClassDesc, MethodTypeDesc> {
41+
TypeDescriptor.OfMethod<ClassDesc, MethodTypeDesc>
42+
permits MethodTypeDescImpl {
4743
/**
4844
* Creates a {@linkplain MethodTypeDesc} given a method descriptor string.
4945
*

0 commit comments

Comments
 (0)