behaviour difference in java 24 when using imports...
Max Rydahl Andersen
manderse at redhat.com
Sun Jun 22 09:02:51 UTC 2025
Hi,
I got reported a "fun" issue on jbang
https://github.com/jbangdev/jbang/issues/2072 which boils down to the
following calls to jshell behaving differently for reasons I can't really
explain.
I've boiled it down to what *looks* like a bug/change of behaviour and
wondering if intentional or not:
Take this code and put in test.jsh (you can also manually type it but whats
the fun in that):
String[] args = { "arg1", "arg2" }
import module java.base;
import static java.util.stream.Collectors.*;
System.out.println(args.length);
/exit
now run this using:
jshell --enable-preview -J--enable-preview --startup=DEFAULT
--execution=local test.jsh
And you will get printed:
2
the correct length of the args array.
Now change it to:
String[] args = { "arg1", "arg2" }
import static java.util.stream.Collectors.*;
import module java.base;
System.out.println(args.length);
/exit
Note, the import order is changed.
Now you get:
WARNING: Using incubator modules: jdk.incubator.vector
Exception java.lang.NullPointerException: Cannot read the array length
because "REPL.$JShell$11B.args" is null
at (#4:1)
question is why is this happening?
Also, if you remove `--startup=DEFAULT` OR `--execution=local` the
behaviour stays the same and 2 is printed in all cases.
Bug or expected ?
Hope it all makes sense :)
--
/max
https://about.me/maxandersen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/kulla-dev/attachments/20250622/617087c4/attachment.htm>
More information about the kulla-dev
mailing list