From 1304b417756c994cbf3a5191d5c86211f8d6773b Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Mon, 9 Dec 2024 08:41:13 +0100 Subject: [PATCH] Replace switch with if/else to avoid potential JIT bug. --- .../dynamic/scaffold/TypeWriter.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java index 0d029601e2..176ab4684d 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java @@ -2509,27 +2509,23 @@ public FieldVisitor visitField(int modifiers, String name, String descriptor, @M if (!type.isInstance(value)) { throw new IllegalStateException("Field " + name + " defines an incompatible default value " + value + " (" + value.getClass().getName() + ")"); } else if (type == Integer.class) { + char character = descriptor.charAt(0); int minimum, maximum; - switch (descriptor.charAt(0)) { - case 'Z': - minimum = 0; - maximum = 1; - break; - case 'B': - minimum = Byte.MIN_VALUE; - maximum = Byte.MAX_VALUE; - break; - case 'C': - minimum = Character.MIN_VALUE; - maximum = Character.MAX_VALUE; - break; - case 'S': - minimum = Short.MIN_VALUE; - maximum = Short.MAX_VALUE; - break; - default: - minimum = Integer.MIN_VALUE; - maximum = Integer.MAX_VALUE; + if (character == 'Z') { + minimum = 0; + maximum = 1; + } else if (character == 'B') { + minimum = Byte.MIN_VALUE; + maximum = Byte.MAX_VALUE; + } else if (character == 'S') { + minimum = Short.MIN_VALUE; + maximum = Short.MAX_VALUE; + } else if (character == 'C') { + minimum = Character.MIN_VALUE; + maximum = Character.MAX_VALUE; + } else { + minimum = Integer.MIN_VALUE; + maximum = Integer.MAX_VALUE; } if ((Integer) value < minimum || (Integer) value > maximum) { throw new IllegalStateException("Field " + name + " defines an incompatible default value " + value + " (" + minimum + "-" + maximum + ")");