Bug in JDK25 with switch statements
forax at univ-mlv.fr
forax at univ-mlv.fr
Fri Mar 21 11:09:17 UTC 2025
> From: "Rafael Winterhalter" <rafael.wth at gmail.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "compiler-dev" <compiler-dev at openjdk.org>
> Sent: Friday, March 21, 2025 11:15:57 AM
> Subject: Re: Bug in JDK25 with switch statements
> (And of course, this is the right list, I originally thought to post this to the
> HotSpot list, but this happens in interpreted mode, so I excluded that.)
> Am Fr., 21. März 2025 um 11:14 Uhr schrieb Rafael Winterhalter < [
> mailto:rafael.wth at gmail.com | rafael.wth at gmail.com ] >:
>> The error is stable and can be reproduced by simply building the project. But it
>> seems to be an issue with javac indeed. The tableswitch statement is compiled
>> as follows.
>> 213: tableswitch { // 100 to 116
>> 100: 322
>> 101: 296
>> 102: 361
>> 103: 335
>> 104: 348
>> 105: 309
>> 106: 374
>> 107: 374
>> 108: 374
>> 109: 374
>> 110: 374
>> 111: 374
>> 112: 374
>> 113: 374
>> 114: 374
>> 115: 374
>> 116: 374
>> default: 374
>> The right branch for 'p' is included at offset 361, but 'p' is an integer value
>> of 109. The character 102 (f) is not included in the Java source.
The table is constructed like if all the targets that correspond to a valid branches (one of the six) are all on top instead of being in front the right value (m, t, d, s, r, p).
Sadly, i'm not able to reproduce the issue, the following code works for me :(
static final char M_SYMBOL = 'm' ;
static final char T_SYMBOL = 't' ;
static final char D_SYMBOL = 'd' ;
static final char S_SYMBOL = 's' ;
static final char R_SYMBOL = 'r' ;
static final char P_SYMBOL = 'p' ;
public static void main ( String [] args ) {
var text = "mtdsrp" ;
for ( var i = 0 ; i < text .length(); i ++) {
switch ( text .charAt( i )) {
case M_SYMBOL :
System . out .println( "m" );
break ;
case T_SYMBOL :
System . out .println( "t" );
break ;
case D_SYMBOL :
System . out .println( "d" );
break ;
case S_SYMBOL :
System . out .println( "s" );
break ;
case R_SYMBOL :
System . out .println( "r" );
break ;
case P_SYMBOL :
System . out .println( "p" );
break ;
default :
throw new IllegalStateException();
}
}
}
>> I guess this is the wrong mailing list in this case. I will post this to the
>> javac list.
>> Thanks, Rafael
>> Am Fr., 21. März 2025 um 10:54 Uhr schrieb Remi Forax < [
>> mailto:forax at univ-mlv.fr | forax at univ-mlv.fr ] >:
>>> Hello Raphael,
>>> It may be hard to reproduce,
>>> can you do a javap -c on the class/method so it will be easier to see if the
>>> generated bytecode is wrong of if it's a VM issue.
>>> regards,
>>> Rémi
>>>> From: "Rafael Winterhalter" < [ mailto:rafael.wth at gmail.com |
>>>> rafael.wth at gmail.com ] >
>>>> To: "compiler-dev" < [ mailto:compiler-dev at openjdk.org |
>>>> compiler-dev at openjdk.org ] >
>>>> Sent: Friday, March 21, 2025 10:20:48 AM
>>>> Subject: Bug in JDK25 with switch statements
>>>> Hello,
>>>> my project Byte Buddy fails to build with recent JDK 25s. I am not sure if this
>>>> is a known bug, but I wanted to mention it: [
>>>> https://github.com/raphw/byte-buddy/actions/runs/13975513319/job/39131008617 |
>>>> https://github.com/raphw/byte-buddy/actions/runs/13975513319/job/39131008617 ]
>>>> The reason for the build failure is that this switch statement ends up in the
>>>> default branch: [
>>>> https://github.com/raphw/byte-buddy/blob/master/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java#L3239
>>>> |
>>>> https://github.com/raphw/byte-buddy/blob/master/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java#L3239
>>>> ]
>>>> This is happening for the char 'p' which is the last legal branch of the switch.
>>>> This does not yield an error on JDKs 5 to 24, so this must be introduced
>>>> recently.
>>>> Thanks, Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20250321/1d233772/attachment.htm>
More information about the compiler-dev
mailing list