possible bug with instanceof pattern matching

Tagir Valeev amaembo at gmail.com
Mon Feb 19 09:19:52 UTC 2024


A side note: you are showing the screenshots from IntelliJ IDEA. Being one
of IntelliJ IDEA developers, I appreciate it. However, please note that
error messages displayed by IntelliJ IDEA in the editor are not originating
from javac. It's an independent implementation of the Java compiler
frontend (except code generation) based on reading the specification and
examining the reference implementation behavior. While we try our best to
implement it correctly, it could differ in details from how the javac
behaves, as there could be bugs in IntelliJ IDEA, or bugs in javac, or
unclear places in the specification. I think that for discussions in this
mailing list, showing messages from javac is more appropriate. If you
prefer using IntelliJ, you may find them in the Build tool window when you
actually build the project.

With best regards,
Tagir Valeev.

On Sun, Feb 18, 2024 at 4:23 PM Charles <im741314 at gmail.com> wrote:

> 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/20240219/0ef16e27/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/20240219/0ef16e27/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/20240219/0ef16e27/image-0003.png>


More information about the amber-dev mailing list