From 43eca1dcb197e3615b6077a5d8aef28f32a7724c Mon Sep 17 00:00:00 2001 From: Adam Sotona Date: Tue, 14 Mar 2023 08:36:05 +0000 Subject: [PATCH] 8303910: jdk/classfile/CorpusTest.java failed 1 of 6754 tests Reviewed-by: jpai --- .../jdk/internal/classfile/TypeKind.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/classfile/TypeKind.java b/src/java.base/share/classes/jdk/internal/classfile/TypeKind.java index 245516b04f8..39a9b656e16 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/TypeKind.java +++ b/src/java.base/share/classes/jdk/internal/classfile/TypeKind.java @@ -50,8 +50,6 @@ public enum TypeKind { /** void */ VoidType("void", "V", -1); - private static TypeKind[] newarraycodeToTypeTag; - private final String name; private final String descriptor; private final int newarraycode; @@ -102,13 +100,17 @@ public enum TypeKind { * @param newarraycode the operand of the {@code newarray} instruction */ public static TypeKind fromNewArrayCode(int newarraycode) { - if (newarraycodeToTypeTag == null) { - newarraycodeToTypeTag = new TypeKind[12]; - for (TypeKind tag : TypeKind.values()) { - if (tag.newarraycode > 0) newarraycodeToTypeTag[tag.newarraycode] = tag; - } - } - return newarraycodeToTypeTag[newarraycode]; + return switch (newarraycode) { + case 4 -> TypeKind.BooleanType; + case 5 -> TypeKind.CharType; + case 6 -> TypeKind.FloatType; + case 7 -> TypeKind.DoubleType; + case 8 -> TypeKind.ByteType; + case 9 -> TypeKind.ShortType; + case 10 -> TypeKind.IntType; + case 11 -> TypeKind.LongType; + default -> throw new IllegalArgumentException("Bad new array code: " + newarraycode); + }; } /** @@ -127,7 +129,7 @@ public enum TypeKind { case 'J' -> TypeKind.LongType; case 'D' -> TypeKind.DoubleType; case 'V' -> TypeKind.VoidType; - default -> throw new IllegalStateException("Bad type: " + s); + default -> throw new IllegalArgumentException("Bad type: " + s); }; } }