|
| 1 | +# Comprehensive Plan for Dropping Java 11 Support (ENG-2665) |
| 2 | + |
| 3 | +## 1. Update Build Configuration |
| 4 | +- **pom.xml:149-153**: Update maven-compiler-plugin from Java 11 to Java 17 |
| 5 | + - Change `<release>11</release>` to `<release>17</release>` |
| 6 | + - Change `<source>11</source>` to `<source>17</source>` |
| 7 | + - Change `<target>11</target>` to `<target>17</target>` |
| 8 | + |
| 9 | +## 2. Update CI/CD Configuration |
| 10 | +- **.github/workflows/test.yml:12**: Remove Java 11 from test matrix |
| 11 | + - Change `version: [ 11, 17, 21, 22 ]` to `version: [ 17, 21, 22 ]` |
| 12 | + |
| 13 | +## 3. Update Documentation |
| 14 | +- **README.md:210**: Change "This API requires Java 11 or greater" to "This API requires Java 17 or greater" |
| 15 | + |
| 16 | +## 4. Version Bump (Breaking Change) |
| 17 | +- **pom.xml:6**: Bump to major version 4.0.0 |
| 18 | +- **README.md:19,32**: Update version in Maven and Gradle examples to 4.0.0 |
| 19 | +- **CHANGELOG.md**: Add entry for 4.0.0 documenting the breaking change |
| 20 | + |
| 21 | +## 5. Java 17 Code Modernizations |
| 22 | + |
| 23 | +### 5.1 Convert Data Classes to Records |
| 24 | +These immutable data classes are perfect candidates for records: |
| 25 | +- **CtrlData.java**: Convert to record (4 final fields with getters) |
| 26 | +- **CacheKey.java**: Convert to record with custom equals/hashCode if needed |
| 27 | +- **DatabaseRecord.java**: Convert to record (2 final fields) |
| 28 | +- **CachedConstructor.java**: Convert to record (4 final fields) |
| 29 | + |
| 30 | +### 5.2 Reflection & Performance Improvements |
| 31 | +- **Consider using MethodHandles**: Replace reflection-based constructor invocation with MethodHandles for better performance |
| 32 | + - In `Decoder.java:437`: Convert `constructor.newInstance(parameters)` to MethodHandle |
| 33 | + - Cache MethodHandles alongside constructors for repeated invocations |
| 34 | +- **Add @Stable annotations**: For frequently accessed final fields to enable JVM optimizations |
| 35 | + |
| 36 | +### 5.3 Pattern Matching for instanceof |
| 37 | +- **Decoder.java:161,322**: Use pattern matching to eliminate casts |
| 38 | +- **Networks.java:99**: Simplify instanceof checks |
| 39 | +- **Reader.java:302**: Use pattern matching |
| 40 | + |
| 41 | +### 5.4 Switch Expressions |
| 42 | +Convert switch statements that return values: |
| 43 | +- **Decoder.java:123,156,263,503,558**: Convert to switch expressions |
| 44 | +- **Reader.java:364**: Convert to switch expression |
| 45 | + |
| 46 | +### 5.5 Collection Factory Methods |
| 47 | +- Replace `Arrays.asList()` with `List.of()` for immutable lists |
| 48 | +- Replace array initializations with collection factories where appropriate |
| 49 | + |
| 50 | +### 5.6 Text Blocks |
| 51 | +- **Decoder.java:448-450**: Use text blocks for multi-line error messages |
| 52 | + |
| 53 | +## 6. Security & Safety Enhancements |
| 54 | + |
| 55 | +### 6.1 Reflection Security |
| 56 | +- Add security checks for reflection operations |
| 57 | +- Consider adding SecurityManager checks if needed |
| 58 | +- Document security implications of reflection usage |
| 59 | + |
| 60 | +### 6.2 Type Safety |
| 61 | +- Use sealed classes for Type enum if appropriate |
| 62 | +- Add stronger type checking with generics improvements |
| 63 | + |
| 64 | +## 7. Testing & Validation |
| 65 | +- Run full test suite with Java 17, 21, and 22 |
| 66 | +- Verify checkstyle compliance |
| 67 | +- Performance benchmarking to ensure improvements |
| 68 | +- Security audit of reflection usage |
| 69 | + |
| 70 | +## Benefits of These Changes: |
| 71 | +1. **Performance**: MethodHandles are faster than reflection for repeated invocations |
| 72 | +2. **Memory**: Records have better memory layout and reduced boilerplate |
| 73 | +3. **Safety**: Pattern matching eliminates ClassCastException risks |
| 74 | +4. **Readability**: Switch expressions and records make code more concise |
| 75 | +5. **Maintainability**: Less boilerplate code to maintain |
| 76 | +6. **Security**: Better control over reflection operations |
| 77 | + |
| 78 | +This is a breaking change warranting version 4.0.0. |
0 commit comments