Skip to content

Commit 1304b41

Browse files
committed
Replace switch with if/else to avoid potential JIT bug.
1 parent e491d45 commit 1304b41

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,27 +2509,23 @@ public FieldVisitor visitField(int modifiers, String name, String descriptor, @M
25092509
if (!type.isInstance(value)) {
25102510
throw new IllegalStateException("Field " + name + " defines an incompatible default value " + value + " (" + value.getClass().getName() + ")");
25112511
} else if (type == Integer.class) {
2512+
char character = descriptor.charAt(0);
25122513
int minimum, maximum;
2513-
switch (descriptor.charAt(0)) {
2514-
case 'Z':
2515-
minimum = 0;
2516-
maximum = 1;
2517-
break;
2518-
case 'B':
2519-
minimum = Byte.MIN_VALUE;
2520-
maximum = Byte.MAX_VALUE;
2521-
break;
2522-
case 'C':
2523-
minimum = Character.MIN_VALUE;
2524-
maximum = Character.MAX_VALUE;
2525-
break;
2526-
case 'S':
2527-
minimum = Short.MIN_VALUE;
2528-
maximum = Short.MAX_VALUE;
2529-
break;
2530-
default:
2531-
minimum = Integer.MIN_VALUE;
2532-
maximum = Integer.MAX_VALUE;
2514+
if (character == 'Z') {
2515+
minimum = 0;
2516+
maximum = 1;
2517+
} else if (character == 'B') {
2518+
minimum = Byte.MIN_VALUE;
2519+
maximum = Byte.MAX_VALUE;
2520+
} else if (character == 'S') {
2521+
minimum = Short.MIN_VALUE;
2522+
maximum = Short.MAX_VALUE;
2523+
} else if (character == 'C') {
2524+
minimum = Character.MIN_VALUE;
2525+
maximum = Character.MAX_VALUE;
2526+
} else {
2527+
minimum = Integer.MIN_VALUE;
2528+
maximum = Integer.MAX_VALUE;
25332529
}
25342530
if ((Integer) value < minimum || (Integer) value > maximum) {
25352531
throw new IllegalStateException("Field " + name + " defines an incompatible default value " + value + " (" + minimum + "-" + maximum + ")");

0 commit comments

Comments
 (0)