Class StrongEncapsulationExamples
java.lang.Object
net.jrodolfo.java_evolution.java17.strong_encapsulation.StrongEncapsulationExamples
Demonstrates Java 17 strong encapsulation with isolated child JVMs.
The child program deliberately attempts deep reflection into
java.lang.String. That is bad production practice, but it is a
faithful way to show what strong encapsulation blocks and how targeted
migration flags behave. Running the probe in a child JVM keeps those command
line flags out of the Maven test JVM.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCaptures child JVM output. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the source code executed by the child JVM.runWithAddExportsOnly(Path workspace) Runs the probe with--add-exportsonly.runWithAddOpens(Path workspace) Runs the probe with a targeted--add-opensmigration flag.runWithIllegalAccessPermit(Path workspace) Runs the probe with the broad--illegal-access=permitflag that is obsolete after Java 17.runWithoutOpens(Path workspace) Runs the probe without module-opening flags.
-
Constructor Details
-
StrongEncapsulationExamples
public StrongEncapsulationExamples()
-
-
Method Details
-
runWithoutOpens
public StrongEncapsulationExamples.CommandResult runWithoutOpens(Path workspace) throws IOException, InterruptedException Runs the probe without module-opening flags.- Parameters:
workspace- directory for the temporary probe source- Returns:
- child JVM result
- Throws:
IOException- when source creation or process launch failsInterruptedException- when interrupted while waiting
-
runWithAddOpens
public StrongEncapsulationExamples.CommandResult runWithAddOpens(Path workspace) throws IOException, InterruptedException Runs the probe with a targeted--add-opensmigration flag.- Parameters:
workspace- directory for the temporary probe source- Returns:
- child JVM result
- Throws:
IOException- when source creation or process launch failsInterruptedException- when interrupted while waiting
-
runWithAddExportsOnly
public StrongEncapsulationExamples.CommandResult runWithAddExportsOnly(Path workspace) throws IOException, InterruptedException Runs the probe with--add-exportsonly.- Parameters:
workspace- directory for the temporary probe source- Returns:
- child JVM result
- Throws:
IOException- when source creation or process launch failsInterruptedException- when interrupted while waiting
-
runWithIllegalAccessPermit
public StrongEncapsulationExamples.CommandResult runWithIllegalAccessPermit(Path workspace) throws IOException, InterruptedException Runs the probe with the broad--illegal-access=permitflag that is obsolete after Java 17.- Parameters:
workspace- directory for the temporary probe source- Returns:
- child JVM result
- Throws:
IOException- when source creation or process launch failsInterruptedException- when interrupted while waiting
-
probeSource
Returns the source code executed by the child JVM.- Returns:
- probe source
-