-
CSR
-
Resolution: Approved
-
P3
-
None
-
behavioral
-
minimal
-
Minor javadoc wording fix represents no compatibility risk.
-
Java API
-
SE
Summary
Allign java.lang.classfile.Signature.ArrayTypeSig::of
constraints check with the javadoc.
Problem
- Javadoc of
java.lang.classfile.Signature.ArrayTypeSig::of
says: "Throws: IllegalArgumentException - if the resulting array type exceeds 255 dimensions". However the constraint check allows to exceed that limit when thecomponentSignature
argument is already an array. - The javadoc does not mention the IllegalArgumentException is thrown when
dims < 1
.
Solution
Fix the constraints check and the javadoc.
Specification
--- a/src/java.base/share/classes/java/lang/classfile/Signature.java
+++ b/src/java.base/share/classes/java/lang/classfile/Signature.java
@@ -417,15 +417,18 @@ public static ArrayTypeSig of(Signature componentSignature) {
* {@return a signature for an array type}
* @param dims the dimension of the array
* @param componentSignature the component type
- * @throws IllegalArgumentException if the resulting array type exceeds
- * 255 dimensions
+ * @throws IllegalArgumentException if {@code dims < 1} or the
+ * resulting array type exceeds 255 dimensions
*/
public static ArrayTypeSig of(int dims, Signature componentSignature) {
requireNonNull(componentSignature);
+ if (componentSignature instanceof SignaturesImpl.ArrayTypeSigImpl arr) {
+ if (dims < 1 || dims > 255 - arr.arrayDepth())
+ throw new IllegalArgumentException("illegal array depth value");
+ return new SignaturesImpl.ArrayTypeSigImpl(dims + arr.arrayDepth(), arr.elemType());
+ }
if (dims < 1 || dims > 255)
throw new IllegalArgumentException("illegal array depth value");
- if (componentSignature instanceof SignaturesImpl.ArrayTypeSigImpl arr)
- return new SignaturesImpl.ArrayTypeSigImpl(dims + arr.arrayDepth(), arr.elemType());
return new SignaturesImpl.ArrayTypeSigImpl(dims, componentSignature);
}
}
- csr of
-
JDK-8357955 java.lang.classfile.Signature.ArrayTypeSig.of IAE not thrown for dims > 255
-
- Resolved
-