Class FinalFieldRestrictionsExamples
java.lang.Object
net.jrodolfo.java_evolution.java26.final_field_restrictions.FinalFieldRestrictionsExamples
Demonstrates Java 26 warnings for deep-reflective mutation of final fields.
The example runs the reflective mutation in a child JVM. That keeps the main Maven test JVM clean while still showing the real Java 26 runtime behavior: final-field mutation still succeeds by default, but the runtime prints a warning and points to explicit enablement for legacy code that still needs the behavior.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult from a childjavacorjavaprocess.static final recordComplete result of a final-field mutation probe. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDescribes the Java 26 behavior.Explains the migration direction.problem()Explains why final-field mutation is being restricted.Source for a small program that mutates a final field through reflection.runDefaultMutationProbe(Path workspace) Compiles and runs a tiny program that mutates a final field reflectively.runExplicitlyEnabledMutationProbe(Path workspace) Runs the same final-field mutation with explicit mutation enablement.
-
Constructor Details
-
FinalFieldRestrictionsExamples
public FinalFieldRestrictionsExamples()
-
-
Method Details
-
runDefaultMutationProbe
public FinalFieldRestrictionsExamples.MutationProbeResult runDefaultMutationProbe(Path workspace) throws IOException, InterruptedException Compiles and runs a tiny program that mutates a final field reflectively.- Parameters:
workspace- temporary directory for generated source and class files- Returns:
- the child compiler and runtime results
- Throws:
IOException- when generated source cannot be written or a child process cannot be startedInterruptedException- when waiting for a child process is interrupted
-
runExplicitlyEnabledMutationProbe
public FinalFieldRestrictionsExamples.MutationProbeResult runExplicitlyEnabledMutationProbe(Path workspace) throws IOException, InterruptedException Runs the same final-field mutation with explicit mutation enablement.- Parameters:
workspace- temporary directory for generated source and class files- Returns:
- the child compiler and runtime results
- Throws:
IOException- when generated source cannot be written or a child process cannot be startedInterruptedException- when waiting for a child process is interrupted
-
reflectiveMutationSource
Source for a small program that mutates a final field through reflection.- Returns:
- generated source used by the child-process probe
-
problem
Explains why final-field mutation is being restricted.- Returns:
- a short problem statement
-
java26Behavior
-
migrationDirection
Explains the migration direction.- Returns:
- a short migration note
-