Skip to content

Commit

Permalink
Replace switch with if/else to avoid potential JIT bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 9, 2024
1 parent e491d45 commit 1304b41
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")");
Expand Down

0 comments on commit 1304b41

Please sign in to comment.