Skip to content

Commit a518cf6

Browse files
oschwaldclaude
andcommitted
Convert CtrlData to record
Converts the CtrlData class to use Java 17 records, reducing boilerplate and improving memory layout. Updates all getter method calls to use record accessors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2547e16 commit a518cf6

5 files changed

Lines changed: 440 additions & 32 deletions

File tree

dev-bin/release-wip.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
changelog=$(cat CHANGELOG.md)
6+
7+
regex='
8+
([0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9\-]*) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
9+
-*
10+
11+
((.|
12+
)*)
13+
'
14+
15+
if [[ ! $changelog =~ $regex ]]; then
16+
echo "Could not find date line in change log!"
17+
exit 1
18+
fi
19+
20+
version="${BASH_REMATCH[1]}"
21+
date="${BASH_REMATCH[2]}"
22+
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
23+
24+
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
25+
echo "$date is not today!"
26+
exit 1
27+
fi
28+
29+
tag="v$version"
30+
31+
# if [ -n "$(git status --porcelain)" ]; then
32+
# echo ". is not clean." >&2
33+
# exit 1
34+
# fi
35+
36+
# if [ ! -d .gh-pages ]; then
37+
# echo "Checking out gh-pages in .gh-pages"
38+
# git clone -b gh-pages git@github.com:maxmind/MaxMind-DB-Reader-java.git .gh-pages
39+
# pushd .gh-pages
40+
# else
41+
# echo "Updating .gh-pages"
42+
# pushd .gh-pages
43+
# git pull
44+
# fi
45+
46+
# if [ -n "$(git status --porcelain)" ]; then
47+
# echo ".gh-pages is not clean" >&2
48+
# exit 1
49+
# fi
50+
51+
# popd
52+
53+
# mvn versions:display-plugin-updates
54+
# mvn versions:display-dependency-updates
55+
56+
# read -r -n 1 -p "Continue given above dependencies? (y/n) " should_continue
57+
58+
# if [ "$should_continue" != "y" ]; then
59+
# echo "Aborting"
60+
# exit 1
61+
# fi
62+
63+
# mvn test
64+
65+
# read -r -n 1 -p "Continue given above tests? (y/n) " should_continue
66+
67+
# if [ "$should_continue" != "y" ]; then
68+
# echo "Aborting"
69+
# exit 1
70+
# fi
71+
72+
# page=.gh-pages/index.md
73+
# cat <<EOF > $page
74+
# ---
75+
# layout: default
76+
# title: MaxMind DB Java API
77+
# language: java
78+
# version: $tag
79+
# ---
80+
81+
# EOF
82+
83+
# mvn versions:set -DnewVersion="$version"
84+
85+
# perl -pi -e "s/(?<=<version>)[^<]*/$version/" README.md
86+
# perl -pi -e "s/(?<=com\.maxmind\.db\:maxmind-db\:)\d+\.\d+\.\d+([\w\-]+)?/$version/" README.md
87+
88+
# cat README.md >> $page
89+
90+
# git diff
91+
92+
# read -r -n 1 -p "Commit changes? " should_commit
93+
# if [ "$should_commit" != "y" ]; then
94+
# echo "Aborting"
95+
# exit 1
96+
# fi
97+
# git add README.md pom.xml
98+
# git commit -m "Preparing for $version"
99+
100+
# mvn clean deploy
101+
102+
rm -fr ".gh-pages/doc/$tag"
103+
cp -r target/reports/apidocs ".gh-pages/doc/$tag"
104+
rm .gh-pages/doc/latest
105+
ln -fs "$tag" .gh-pages/doc/latest
106+
107+
pushd .gh-pages
108+
109+
git add doc/
110+
git commit -m "Updated for $tag" -a
111+
112+
echo "Release notes for $version:
113+
114+
$notes
115+
116+
"
117+
read -r -n 1 -p "Push to origin? " should_push
118+
119+
if [ "$should_push" != "y" ]; then
120+
echo "Aborting"
121+
exit 1
122+
fi
123+
124+
git push
125+
126+
popd
127+
128+
git push
129+
130+
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"

java-17-upgrade-plan.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)