docker-library / openjdk

Docker Official Image packaging for EA builds of OpenJDK from Oracle
http://openjdk.java.net
MIT License
1.14k stars 471 forks source link

openjdk:17-alpine3.14 image cannot compile sealed classes ("sealed classes are a preview feature") #521

Closed tompaz3 closed 1 year ago

tompaz3 commented 1 year ago

It's not a big issue, but someone might have this problem sooner or later and maybe it's good that it was to be found somewhere in the Internet.

I've recently tried to compile my JDK17 project with openjdk:17-alpine3.14 docker image.

To my surprise, it wouldn't compile sealed classes, which were released as a feature (not preview feature) in JDK 17.

Running the following command:

docker run --rm -v $PWD:/tmp/src -w /tmp/src openjdk:17-alpine3.14 ./mvnw clean install

ended with this error:

[INFO] Compiling 1 source file to /tmp/src/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /tmp/src/src/main/java/com/tp/samples/openjdk17sealedclass/DoesNotCompileSample.java:[5,12] sealed classes are a preview feature and are disabled by default.
  (use --enable-preview to enable sealed classes)
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.553 s
[INFO] Finished at: 2022-12-13T21:57:41Z
[INFO] ------------------------------------------------------------------------

I created a minimal reproducible project here: openjdk:17-alpine3.14 sealed classes error.

It's not a big deal, because I wouldn't use such image bare bones in production. It's just a minor inconvenience. I know this particular image might not be even maintained anymore and do not expect any fix. Just wanted to leave this issue for potential unfortunate souls who'd stumble upon the same error in the future.

Cheers

tianon commented 1 year ago

Unfortunately, openjdk:17 is unmaintained here (as is Alpine 3.14 :grimacing:).

I would suggest switching to eclipse-temurin:17-jdk-alpine, which is still maintained.