Files
javademos/structured-concurrency-final/output/11-preview-traps.txt
T
Claude c93a1fffbb Add structured-concurrency-final module: StructuredTaskScope final in JDK 28 (JEP 543), run on 28-ea, 27, 26 and 25
Runnable demos for the ankurm.com structured-concurrency-java article: the ExecutorService thread leak and its fix, every built-in Joiner,
structure violations, timeouts, a custom Joiner, JSON thread dumps (in-process and jcmd), scoped values, javap diffs of the API on 25, 26, 27 and 28-ea,
compiler output for six pieces of 25/26-era code, and the preview class-file trap between 27 and 28. Transcripts in output/.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CifR2BE7PBvRy5hT8TS9oz
2026-10-26 02:01:31 +00:00

60 lines
3.2 KiB
Plaintext

# compile on 27 with preview, then run the class file on 27 and on 28
$ java --enable-preview Server (27.0.1.0.2+1)
Response[user=Alice, order=42]
Runtime: 27.0.1.0.2+1
$ java --enable-preview Server (28-beta+21-ea)
Error: LinkageError occurred while loading main class Server
java.lang.UnsupportedClassVersionError: Server (class file version 71.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 72.65535
$ java Server (27.0.1.0.2+1)
Error: LinkageError occurred while loading main class Server
java.lang.UnsupportedClassVersionError: Preview features are not enabled for Server (class file version 71.65535). Try running with '--enable-preview'
# the class file's minor version
minor version: 65535
major version: 71
# javac 28 asked for --release 27
$ javac --release 27 src/Server.java (28-beta+21-ea)
src/Server.java:2: error: StructuredTaskScope is a preview API and is disabled by default.
import java.util.concurrent.StructuredTaskScope;
^
(use --enable-preview to enable preview APIs)
src/Server.java:3: error: StructuredTaskScope is a preview API and is disabled by default.
import java.util.concurrent.StructuredTaskScope.Subtask;
^
(use --enable-preview to enable preview APIs)
src/Server.java:3: error: Subtask is a preview API and is disabled by default.
import java.util.concurrent.StructuredTaskScope.Subtask;
^
(use --enable-preview to enable preview APIs)
src/Server.java:22: error: StructuredTaskScope is a preview API and is disabled by default.
try (var scope = StructuredTaskScope.open()) { // 1. open
^
(use --enable-preview to enable preview APIs)
src/Server.java:23: error: Subtask is a preview API and is disabled by default.
Subtask<String> user = scope.fork(this::findUser); // 2. fork
^
(use --enable-preview to enable preview APIs)
src/Server.java:24: error: Subtask is a preview API and is disabled by default.
Subtask<Integer> order = scope.fork(this::fetchOrder); // fork
^
(use --enable-preview to enable preview APIs)
6 errors
# javac 28 with --enable-preview --release 28 on the same file (nothing in it needs preview)
$ javac --enable-preview --release 28 src/Server.java (28-beta+21-ea)
Note: src/Server.java uses preview features of Java SE 28.
Note: Recompile with -Xlint:preview for details.
exit=0
# where that Note comes from: the first lines of -Xlint:preview
$ javac --enable-preview --release 28 -Xlint:preview src/Server.java 2>&1 | head -3 (28-beta+21-ea)
warning: [preview] class file for /@/java.base/java/lang/Record.sig uses preview features of Java SE 28.
warning: [preview] class file for /@/java.base/java/time/Duration.sig uses preview features of Java SE 28.
warning: [preview] class file for /@/java.base/java/lang/Integer.sig uses preview features of Java SE 28.
# recompile on 28 without any flag and run on 28
$ javac src/Server.java && java Server (28-beta+21-ea)
Response[user=Alice, order=42]
Runtime: 28-beta+21-ea