8329099: Undocumented exception thrown by Instruction factory methods accepting Opcode

Reviewed-by: briangoetz
This commit is contained in:
Adam Sotona 2024-04-16 08:23:31 +00:00
parent def257727d
commit 97c180892b
17 changed files with 48 additions and 0 deletions

View File

@ -54,6 +54,8 @@ public sealed interface ArrayLoadInstruction extends Instruction
* *
* @param op the opcode for the specific type of array load instruction, * @param op the opcode for the specific type of array load instruction,
* which must be of kind {@link Opcode.Kind#ARRAY_LOAD} * which must be of kind {@link Opcode.Kind#ARRAY_LOAD}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#ARRAY_LOAD}.
*/ */
static ArrayLoadInstruction of(Opcode op) { static ArrayLoadInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.ARRAY_LOAD); Util.checkKind(op, Opcode.Kind.ARRAY_LOAD);

View File

@ -54,6 +54,8 @@ public sealed interface ArrayStoreInstruction extends Instruction
* *
* @param op the opcode for the specific type of array store instruction, * @param op the opcode for the specific type of array store instruction,
* which must be of kind {@link Opcode.Kind#ARRAY_STORE} * which must be of kind {@link Opcode.Kind#ARRAY_STORE}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#ARRAY_STORE}.
*/ */
static ArrayStoreInstruction of(Opcode op) { static ArrayStoreInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.ARRAY_STORE); Util.checkKind(op, Opcode.Kind.ARRAY_STORE);

View File

@ -56,6 +56,8 @@ public sealed interface BranchInstruction extends Instruction
* @param op the opcode for the specific type of branch instruction, * @param op the opcode for the specific type of branch instruction,
* which must be of kind {@link Opcode.Kind#BRANCH} * which must be of kind {@link Opcode.Kind#BRANCH}
* @param target the target of the branch * @param target the target of the branch
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#BRANCH}.
*/ */
static BranchInstruction of(Opcode op, Label target) { static BranchInstruction of(Opcode op, Label target) {
Util.checkKind(op, Opcode.Kind.BRANCH); Util.checkKind(op, Opcode.Kind.BRANCH);

View File

@ -131,6 +131,8 @@ public sealed interface ConstantInstruction extends Instruction {
* *
* @param op the opcode for the specific type of intrinsic constant instruction, * @param op the opcode for the specific type of intrinsic constant instruction,
* which must be of kind {@link Opcode.Kind#CONSTANT} * which must be of kind {@link Opcode.Kind#CONSTANT}
* @throws IllegalArgumentException if the opcode does not represent a constant
* with implicit value
*/ */
static IntrinsicConstantInstruction ofIntrinsic(Opcode op) { static IntrinsicConstantInstruction ofIntrinsic(Opcode op) {
Util.checkKind(op, Opcode.Kind.CONSTANT); Util.checkKind(op, Opcode.Kind.CONSTANT);
@ -145,6 +147,8 @@ public sealed interface ConstantInstruction extends Instruction {
* @param op the opcode for the specific type of intrinsic constant instruction, * @param op the opcode for the specific type of intrinsic constant instruction,
* which must be of kind {@link Opcode.Kind#CONSTANT} * which must be of kind {@link Opcode.Kind#CONSTANT}
* @param value the constant value * @param value the constant value
* @throws IllegalArgumentException if the opcode is not {@link Opcode#BIPUSH}
* or {@link Opcode#SIPUSH}
*/ */
static ArgumentConstantInstruction ofArgument(Opcode op, int value) { static ArgumentConstantInstruction ofArgument(Opcode op, int value) {
Util.checkKind(op, Opcode.Kind.CONSTANT); Util.checkKind(op, Opcode.Kind.CONSTANT);
@ -159,6 +163,8 @@ public sealed interface ConstantInstruction extends Instruction {
* @param op the opcode for the specific type of load constant instruction, * @param op the opcode for the specific type of load constant instruction,
* which must be of kind {@link Opcode.Kind#CONSTANT} * which must be of kind {@link Opcode.Kind#CONSTANT}
* @param constant the constant value * @param constant the constant value
* @throws IllegalArgumentException if the opcode is not {@link Opcode#LDC},
* {@link Opcode#LDC_W}, or {@link Opcode#LDC2_W}
*/ */
static LoadConstantInstruction ofLoad(Opcode op, LoadableConstantEntry constant) { static LoadConstantInstruction ofLoad(Opcode op, LoadableConstantEntry constant) {
Util.checkKind(op, Opcode.Kind.CONSTANT); Util.checkKind(op, Opcode.Kind.CONSTANT);

View File

@ -70,6 +70,8 @@ public sealed interface ConvertInstruction extends Instruction
* *
* @param op the opcode for the specific type of conversion instruction, * @param op the opcode for the specific type of conversion instruction,
* which must be of kind {@link Opcode.Kind#CONVERT} * which must be of kind {@link Opcode.Kind#CONVERT}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#CONVERT}.
*/ */
static ConvertInstruction of(Opcode op) { static ConvertInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.CONVERT); Util.checkKind(op, Opcode.Kind.CONVERT);

View File

@ -68,6 +68,8 @@ public sealed interface DiscontinuedInstruction extends Instruction {
* @param op the opcode for the specific type of JSR instruction, * @param op the opcode for the specific type of JSR instruction,
* which must be of kind {@link Opcode.Kind#DISCONTINUED_JSR} * which must be of kind {@link Opcode.Kind#DISCONTINUED_JSR}
* @param target target label of the subroutine * @param target target label of the subroutine
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#DISCONTINUED_JSR}.
*/ */
static JsrInstruction of(Opcode op, Label target) { static JsrInstruction of(Opcode op, Label target) {
Util.checkKind(op, Opcode.Kind.DISCONTINUED_JSR); Util.checkKind(op, Opcode.Kind.DISCONTINUED_JSR);
@ -109,6 +111,8 @@ public sealed interface DiscontinuedInstruction extends Instruction {
* @param op the opcode for the specific type of RET instruction, * @param op the opcode for the specific type of RET instruction,
* which must be of kind {@link Opcode.Kind#DISCONTINUED_RET} * which must be of kind {@link Opcode.Kind#DISCONTINUED_RET}
* @param slot the local variable slot to load return address from * @param slot the local variable slot to load return address from
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#DISCONTINUED_RET}.
*/ */
static RetInstruction of(Opcode op, int slot) { static RetInstruction of(Opcode op, int slot) {
Util.checkKind(op, Opcode.Kind.DISCONTINUED_RET); Util.checkKind(op, Opcode.Kind.DISCONTINUED_RET);

View File

@ -89,6 +89,8 @@ public sealed interface FieldInstruction extends Instruction
* @param op the opcode for the specific type of field access instruction, * @param op the opcode for the specific type of field access instruction,
* which must be of kind {@link Opcode.Kind#FIELD_ACCESS} * which must be of kind {@link Opcode.Kind#FIELD_ACCESS}
* @param field a constant pool entry describing the field * @param field a constant pool entry describing the field
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#FIELD_ACCESS}.
*/ */
static FieldInstruction of(Opcode op, FieldRefEntry field) { static FieldInstruction of(Opcode op, FieldRefEntry field) {
Util.checkKind(op, Opcode.Kind.FIELD_ACCESS); Util.checkKind(op, Opcode.Kind.FIELD_ACCESS);

View File

@ -104,6 +104,8 @@ public sealed interface InvokeInstruction extends Instruction
* @param op the opcode for the specific type of invocation instruction, * @param op the opcode for the specific type of invocation instruction,
* which must be of kind {@link Opcode.Kind#INVOKE} * which must be of kind {@link Opcode.Kind#INVOKE}
* @param method a constant pool entry describing the method * @param method a constant pool entry describing the method
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#INVOKE}.
*/ */
static InvokeInstruction of(Opcode op, MemberRefEntry method) { static InvokeInstruction of(Opcode op, MemberRefEntry method) {
Util.checkKind(op, Opcode.Kind.INVOKE); Util.checkKind(op, Opcode.Kind.INVOKE);

View File

@ -73,6 +73,8 @@ public sealed interface LoadInstruction extends Instruction
* @param op the opcode for the specific type of load instruction, * @param op the opcode for the specific type of load instruction,
* which must be of kind {@link Opcode.Kind#LOAD} * which must be of kind {@link Opcode.Kind#LOAD}
* @param slot the local variable slot to load from * @param slot the local variable slot to load from
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#LOAD}.
*/ */
static LoadInstruction of(Opcode op, int slot) { static LoadInstruction of(Opcode op, int slot) {
Util.checkKind(op, Opcode.Kind.LOAD); Util.checkKind(op, Opcode.Kind.LOAD);

View File

@ -48,6 +48,8 @@ public sealed interface MonitorInstruction extends Instruction
* *
* @param op the opcode for the specific type of monitor instruction, * @param op the opcode for the specific type of monitor instruction,
* which must be of kind {@link Opcode.Kind#MONITOR} * which must be of kind {@link Opcode.Kind#MONITOR}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#MONITOR}.
*/ */
static MonitorInstruction of(Opcode op) { static MonitorInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.MONITOR); Util.checkKind(op, Opcode.Kind.MONITOR);

View File

@ -51,8 +51,14 @@ public sealed interface NewPrimitiveArrayInstruction extends Instruction
* {@return a new primitive array instruction} * {@return a new primitive array instruction}
* *
* @param typeKind the component type of the array * @param typeKind the component type of the array
* @throws IllegalArgumentException when the {@code typeKind} is not a legal
* primitive array component type
*/ */
static NewPrimitiveArrayInstruction of(TypeKind typeKind) { static NewPrimitiveArrayInstruction of(TypeKind typeKind) {
// Implicit null-check:
if (typeKind.newarraycode() < 0) {
throw new IllegalArgumentException("Illegal component type: " + typeKind.typeName());
}
return new AbstractInstruction.UnboundNewPrimitiveArrayInstruction(typeKind); return new AbstractInstruction.UnboundNewPrimitiveArrayInstruction(typeKind);
} }
} }

View File

@ -54,6 +54,8 @@ public sealed interface OperatorInstruction extends Instruction
* *
* @param op the opcode for the specific type of array load instruction, * @param op the opcode for the specific type of array load instruction,
* which must be of kind {@link Opcode.Kind#OPERATOR} * which must be of kind {@link Opcode.Kind#OPERATOR}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#OPERATOR}.
*/ */
static OperatorInstruction of(Opcode op) { static OperatorInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.OPERATOR); Util.checkKind(op, Opcode.Kind.OPERATOR);

View File

@ -65,6 +65,8 @@ public sealed interface ReturnInstruction extends Instruction
* *
* @param op the opcode for the specific type of return instruction, * @param op the opcode for the specific type of return instruction,
* which must be of kind {@link Opcode.Kind#RETURN} * which must be of kind {@link Opcode.Kind#RETURN}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#RETURN}.
*/ */
static ReturnInstruction of(Opcode op) { static ReturnInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.RETURN); Util.checkKind(op, Opcode.Kind.RETURN);

View File

@ -49,6 +49,8 @@ public sealed interface StackInstruction extends Instruction
* *
* @param op the opcode for the specific type of stack instruction, * @param op the opcode for the specific type of stack instruction,
* which must be of kind {@link Opcode.Kind#STACK} * which must be of kind {@link Opcode.Kind#STACK}
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#STACK}.
*/ */
static StackInstruction of(Opcode op) { static StackInstruction of(Opcode op) {
Util.checkKind(op, Opcode.Kind.STACK); Util.checkKind(op, Opcode.Kind.STACK);

View File

@ -72,6 +72,8 @@ public sealed interface StoreInstruction extends Instruction
* @param op the opcode for the specific type of store instruction, * @param op the opcode for the specific type of store instruction,
* which must be of kind {@link Opcode.Kind#STORE} * which must be of kind {@link Opcode.Kind#STORE}
* @param slot the local variable slot to store to * @param slot the local variable slot to store to
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#STORE}.
*/ */
static StoreInstruction of(Opcode op, int slot) { static StoreInstruction of(Opcode op, int slot) {
Util.checkKind(op, Opcode.Kind.STORE); Util.checkKind(op, Opcode.Kind.STORE);

View File

@ -59,6 +59,8 @@ public sealed interface TypeCheckInstruction extends Instruction
* @param op the opcode for the specific type of type check instruction, * @param op the opcode for the specific type of type check instruction,
* which must be of kind {@link Opcode.Kind#TYPE_CHECK} * which must be of kind {@link Opcode.Kind#TYPE_CHECK}
* @param type the type against which to check or cast * @param type the type against which to check or cast
* @throws IllegalArgumentException if the opcode kind is not
* {@link Opcode.Kind#TYPE_CHECK}.
*/ */
static TypeCheckInstruction of(Opcode op, ClassEntry type) { static TypeCheckInstruction of(Opcode op, ClassEntry type) {
Util.checkKind(op, Opcode.Kind.TYPE_CHECK); Util.checkKind(op, Opcode.Kind.TYPE_CHECK);

View File

@ -238,6 +238,12 @@
* the convenience method {@code CodeBuilder.invokeInstruction}, which in turn behaves * the convenience method {@code CodeBuilder.invokeInstruction}, which in turn behaves
* as if it calls method {@code CodeBuilder.with}. This composing of method calls on the * as if it calls method {@code CodeBuilder.with}. This composing of method calls on the
* builder enables the composing of transforms (as described later). * builder enables the composing of transforms (as described later).
* <p>
* Unless otherwise noted, passing a {@code null} argument to a constructor
* or method of any Class-File API class or interface will cause a {@link
* java.lang.NullPointerException NullPointerException} to be thrown. Additionally,
* invoking a method with an array or collection containing a {@code null} element
* will cause a {@code NullPointerException}, unless otherwise specified. </p>
* *
* <h3>Symbolic information</h3> * <h3>Symbolic information</h3>
* To describe symbolic information for classes and types, the API uses the * To describe symbolic information for classes and types, the API uses the