Class FinalFieldRestrictionsExamples

java.lang.Object
net.jrodolfo.java_evolution.java26.final_field_restrictions.FinalFieldRestrictionsExamples

public class FinalFieldRestrictionsExamples extends Object
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.

  • Constructor Details

    • FinalFieldRestrictionsExamples

      public FinalFieldRestrictionsExamples()
  • Method Details

    • runDefaultMutationProbe

      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 started
      InterruptedException - 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 started
      InterruptedException - when waiting for a child process is interrupted
    • reflectiveMutationSource

      public String reflectiveMutationSource()
      Source for a small program that mutates a final field through reflection.
      Returns:
      generated source used by the child-process probe
    • problem

      public String problem()
      Explains why final-field mutation is being restricted.
      Returns:
      a short problem statement
    • java26Behavior

      public String java26Behavior()
      Describes the Java 26 behavior.
      Returns:
      a short behavior note
    • migrationDirection

      public String migrationDirection()
      Explains the migration direction.
      Returns:
      a short migration note