File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ This repository contains Java examples that are designed to track and document t
1111## Specifications & Practices
1212
1313* [ Java 26] ( java-26/ ) (March, 2026)
14-
14+ * [ JEP 500 ] ( java-26/src/main/java/JEP500PrepareToMakeFinalMeanFinal.java ) : Prepare to Make Final Mean Final
1515* [ Java 25] ( java-25/ ) (September, 2025)
1616 * [ JEP 513] ( java-25/src/main/java/JEP513FlexibleConstructorBodies.java ) : Flexible Constructor Bodies
1717 * [ JEP 512] ( java-25/src/main/java/JEP512CompactSourceFilesAndInstanceMainMethods.java ) : Compact Source Files and Instance Main Methods
Original file line number Diff line number Diff line change 1+ import java .lang .reflect .Field ;
2+
3+ // JEP 500: Prepare to Make Final Mean Final
4+ // https://openjdk.org/jeps/500
5+
6+ public class JEP500PrepareToMakeFinalMeanFinal {
7+ static void main () {
8+ AppConfig config = new AppConfig ();
9+ System .out .println ("1. Original Value: " + config .dbUrl );
10+ try {
11+ // We capture the 'dbUrl' field using the Reflection API
12+ Field field = AppConfig .class .getDeclaredField ("dbUrl" );
13+
14+ // We disable Java's access checks (Opening the backdoor)
15+ field .setAccessible (true );
16+
17+ // We force (hack) a change to the value of the 'final' variable
18+ field .set (config , "jdbc:mysql://hacked-server:3306/stolen_db" );
19+
20+ System .out .println ("2. New Value (Changed): " + config .dbUrl );
21+
22+ } catch (Exception e ) {
23+ e .printStackTrace ();
24+ }
25+ }
26+ }
27+
28+ class AppConfig {
29+ public final String dbUrl = "jdbc:postgresql://localhost:5432/mydb" ;
30+ }
You can’t perform that action at this time.
0 commit comments