possible bug with instanceof pattern matching
Charles
im741314 at gmail.com
Sun Feb 18 11:53:56 UTC 2024
Hi all
What I'm about to report below is *openjdk 17*.
This doesn't compile
if (ex instanceof JedisException je
|| (ex instanceof ExecutionException ee &&
ee.getCause() instanceof JedisException je)
){
... blah blah
}
reason being the second je is already defined in the scope.
[image: image.png]
if you think about it. if ex is je, then, the second part won't trigger.
And if the second part is reached, then ex is not je. Hence there is only
going to be one statement mapped to je.
no confusion here. I feel this should be allowed.
Let's assume the above is the way it should be. I use different names for
the second variable.
if (ex instanceof JedisException je
|| (ex instanceof ExecutionException ee &&
ee.getCause() instanceof JedisException second_je)
) {
log.error(je);
log.error(second_je);
}
[image: image.png]
This still doesn't compile.
I would like to bring this issue up for discussion.
and as always, have a great day
*Best Regards*
*Charles*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240218/b40642ec/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 37408 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240218/b40642ec/image-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 33303 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240218/b40642ec/image-0003.png>
More information about the amber-dev
mailing list