-
CSR
-
Resolution: Approved
-
P4
-
None
-
source, binary, behavioral
-
minimal
-
-
Java API
-
SE
Summary
Update TypeKind's method names and API specification to address issues with TypeKind.
Problem
- TypeKind::newarraycode and TypeKind::fromNewArrayCode have name discrepancies.
- TypeKind::fromDescriptor(String) throws undocumented IndexOutOfBoundsException instead of IllegalArgumentException.
Solution
- Rename the methods to newarrayCode and fromNewarrayCode.
newarray
is a whole word as it's the name of an instruction. - Specify that TypeKind::fromDescriptor may throw IllegalArgumentException if the descriptor string is invalid (but is not required to do so)
Specification
--- a/src/java.base/share/classes/java/lang/classfile/TypeKind.java
+++ b/src/java.base/share/classes/java/lang/classfile/TypeKind.java
@@ -66,9 +66,12 @@ public enum TypeKind {
/** {@return the field descriptor character corresponding to this type} */
public String descriptor() { return descriptor; }
- /** {@return the code used by the {@code newarray} opcode corresponding to this type} */
- public int newarraycode() {
- return newarraycode;
+ /**
+ * {@return the code used by the {@code newarray} opcode corresponding to this type}
+ * @since 23
+ */
+ public int newarrayCode() {
+ return newarrayCode;
}
/**
@@ -94,19 +97,21 @@ public TypeKind asLoadable() {
/**
* {@return the type kind associated with the array type described by the
* array code used as an operand to {@code newarray}}
- * @param newarraycode the operand of the {@code newarray} instruction
+ * @param newarrayCode the operand of the {@code newarray} instruction
+ * @throws IllegalArgumentException if the code is invalid
+ * @since 23
*/
- public static TypeKind fromNewArrayCode(int newarraycode) {
- return switch (newarraycode) {
+ public static TypeKind fromNewarrayCode(int newarrayCode) {
+ return switch (newarrayCode) {
case 4 -> TypeKind.BooleanType;
case 5 -> TypeKind.CharType;
case 6 -> TypeKind.FloatType;
@@ -115,15 +120,19 @@ public static TypeKind fromNewArrayCode(int newarraycode) {
/**
* {@return the type kind associated with the specified field descriptor}
* @param s the field descriptor
+ * @throws IllegalArgumentException only if the descriptor is not valid
*/
public static TypeKind fromDescriptor(CharSequence s) {
+ if (s.isEmpty()) { // implicit null check
+ throw new IllegalArgumentException("Empty descriptor");
+ }
return switch (s.charAt(0)) {
case '[', 'L' -> TypeKind.ReferenceType;
case 'B' -> TypeKind.ByteType;
- csr of
-
JDK-8331744 java.lang.classfile.TypeKind improvements
-
- Resolved
-
- relates to
-
JDK-8324965 JEP 466: Class-File API (Second Preview)
-
- Closed
-