ServiceLoader fails for Java 23 with preview enabled
Robert Scholte
rfscholte at apache.org
Sun Oct 13 11:53:44 UTC 2024
Hi,
It seems there's a change in the ServiceLoader, and it looks like regression
to me.
I've created a small project to reproduce it (I can provide it if wanted and
confirmed this is indeed a bug).
What it basically does is just:
ServiceLoader.load(Car.class).findFirst().orElseThrow();
This succeeds with OpenJDK 22 (with and without preview enabled flag)
It also succeeds with OpenJDK 23 without the preview flag.
However, when adding the preview flag I get:
java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.orElseThrow(Optional.java:377)
at
nl.sourcegrounds.serviceloader.tck.CarTest.<init>(CarTest.java:16)
Anyone who can already explain this with this small amount of information?
Thanks,
Robert Scholte
These are the details for both versions (Windows OS)
openjdk version "22" 2024-03-19
OpenJDK Runtime Environment (build 22+36-2370)
OpenJDK 64-Bit Server VM (build 22+36-2370, mixed mode, sharing)
openjdk version "23" 2024-09-17
OpenJDK Runtime Environment (build 23+37-2369)
OpenJDK 64-Bit Server VM (build 23+37-2369, mixed mode, sharing)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20241013/220668b6/attachment-0001.htm>
More information about the core-libs-dev
mailing list