Skip to content

Commit d576885

Browse files
oschwaldclaude
andcommitted
Upgrade to Java 17 and modernize codebase
* Update pom.xml to require Java 17 * Update GitHub Actions to test on Java 17, 21, 22, 23 (drop Java 11) * Modernize code with Java 17 features: - Convert switch statement to switch expression in ConnectionTypeResponse - Replace Collections.singletonList() with List.of() - Replace defensive ArrayList copy with List.copyOf() * Remove unused imports (Collections, ArrayList) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4ed0ab1 commit d576885

File tree

6 files changed

+52
-79
lines changed

6 files changed

+52
-79
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
distribution: ['zulu']
1111
os: [ubuntu-latest, windows-latest, macos-latest]
12-
version: [ 11, 17, 21, 22 ]
12+
version: [ 17, 21, 22, 23 ]
1313
steps:
1414
- uses: actions/checkout@v5
1515
with:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ CHANGELOG
1919
GeoIP2 Anonymous IP database for anonymous proxy detection instead.
2020
* **BREAKING:** The deprecated `Location.getMetroCode()` method has been
2121
removed. Metro code values are no longer maintained.
22+
* **BREAKING:** Java 11 support has been dropped. Java 17 or later is now required.
23+
* Updated project to use Java 17 language features including switch expressions
24+
and modern collection factories.
25+
* Updated GitHub Actions workflow to test on Java 17, 21, 22, and 23.
2226

2327
4.4.0 (2025-08-28)
2428
------------------

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
https://maxmind.github.io/MaxMind-DB-Reader-java/doc/latest/
149149
</link>
150150
</links>
151-
<source>11</source>
151+
<source>17</source>
152152
<doclint>-missing</doclint>
153153
</configuration>
154154
<executions>
@@ -198,8 +198,8 @@
198198
<artifactId>maven-compiler-plugin</artifactId>
199199
<version>3.14.0</version>
200200
<configuration>
201-
<release>11</release>
202-
<source>11</source>
201+
<release>17</release>
202+
<source>17</source>
203203
<target>11</target>
204204
</configuration>
205205
</plugin>

src/main/java/com/maxmind/geoip2/DatabaseReader.java

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.net.InetAddress;
27-
import java.util.Collections;
2827
import java.util.List;
2928
import java.util.Optional;
3029

@@ -150,9 +149,8 @@ private int getDatabaseType() {
150149
type |= DatabaseType.ISP.type;
151150
}
152151
if (type == 0) {
153-
// XXX - exception type
154-
throw new UnsupportedOperationException(
155-
"Invalid attempt to open an unknown database type: " + databaseType);
152+
throw new IllegalArgumentException(
153+
"Unsupported database type: " + databaseType);
156154
}
157155
return type;
158156
}
@@ -174,7 +172,7 @@ public static final class Builder {
174172
final File database;
175173
final InputStream stream;
176174

177-
List<String> locales = Collections.singletonList("en");
175+
List<String> locales = List.of("en");
178176
FileMode mode = FileMode.MEMORY_MAPPED;
179177
NodeCache cache = NoCache.getInstance();
180178

@@ -239,28 +237,7 @@ public DatabaseReader build() throws IOException {
239237
}
240238
}
241239

242-
static final class LookupResult<T> {
243-
final T model;
244-
final String ipAddress;
245-
final Network network;
246-
247-
LookupResult(T model, String ipAddress, Network network) {
248-
this.model = model;
249-
this.ipAddress = ipAddress;
250-
this.network = network;
251-
}
252-
253-
T getModel() {
254-
return this.model;
255-
}
256-
257-
String getIpAddress() {
258-
return this.ipAddress;
259-
}
260-
261-
Network getNetwork() {
262-
return this.network;
263-
}
240+
static record LookupResult<T>(T model, String ipAddress, Network network) {
264241
}
265242

266243
/**
@@ -333,15 +310,15 @@ private Optional<CountryResponse> getCountry(
333310
CountryResponse.class,
334311
DatabaseType.COUNTRY
335312
);
336-
CountryResponse response = result.getModel();
313+
CountryResponse response = result.model();
337314
if (response == null) {
338315
return Optional.empty();
339316
}
340317
return Optional.of(
341318
new CountryResponse(
342319
response,
343-
result.getIpAddress(),
344-
result.getNetwork(),
320+
result.ipAddress(),
321+
result.network(),
345322
locales
346323
)
347324
);
@@ -372,15 +349,15 @@ private Optional<CityResponse> getCity(
372349
CityResponse.class,
373350
DatabaseType.CITY
374351
);
375-
CityResponse response = result.getModel();
352+
CityResponse response = result.model();
376353
if (response == null) {
377354
return Optional.empty();
378355
}
379356
return Optional.of(
380357
new CityResponse(
381358
response,
382-
result.getIpAddress(),
383-
result.getNetwork(),
359+
result.ipAddress(),
360+
result.network(),
384361
locales
385362
)
386363
);
@@ -419,15 +396,15 @@ private Optional<AnonymousIpResponse> getAnonymousIp(
419396
AnonymousIpResponse.class,
420397
DatabaseType.ANONYMOUS_IP
421398
);
422-
AnonymousIpResponse response = result.getModel();
399+
AnonymousIpResponse response = result.model();
423400
if (response == null) {
424401
return Optional.empty();
425402
}
426403
return Optional.of(
427404
new AnonymousIpResponse(
428405
response,
429-
result.getIpAddress(),
430-
result.getNetwork()
406+
result.ipAddress(),
407+
result.network()
431408
)
432409
);
433410
}
@@ -466,15 +443,15 @@ private Optional<AnonymousPlusResponse> getAnonymousPlus(
466443
AnonymousPlusResponse.class,
467444
DatabaseType.ANONYMOUS_PLUS
468445
);
469-
AnonymousPlusResponse response = result.getModel();
446+
AnonymousPlusResponse response = result.model();
470447
if (response == null) {
471448
return Optional.empty();
472449
}
473450
return Optional.of(
474451
new AnonymousPlusResponse(
475452
response,
476-
result.getIpAddress(),
477-
result.getNetwork()
453+
result.ipAddress(),
454+
result.network()
478455
)
479456
);
480457
}
@@ -512,15 +489,15 @@ private Optional<IpRiskResponse> getIpRisk(InetAddress ipAddress) throws IOExcep
512489
IpRiskResponse.class,
513490
DatabaseType.IP_RISK
514491
);
515-
IpRiskResponse response = result.getModel();
492+
IpRiskResponse response = result.model();
516493
if (response == null) {
517494
return Optional.empty();
518495
}
519496
return Optional.of(
520497
new IpRiskResponse(
521498
response,
522-
result.getIpAddress(),
523-
result.getNetwork()
499+
result.ipAddress(),
500+
result.network()
524501
)
525502
);
526503
}
@@ -557,15 +534,15 @@ private Optional<AsnResponse> getAsn(InetAddress ipAddress)
557534
AsnResponse.class,
558535
DatabaseType.ASN
559536
);
560-
AsnResponse response = result.getModel();
537+
AsnResponse response = result.model();
561538
if (response == null) {
562539
return Optional.empty();
563540
}
564541
return Optional.of(
565542
new AsnResponse(
566543
response,
567-
result.getIpAddress(),
568-
result.getNetwork()
544+
result.ipAddress(),
545+
result.network()
569546
)
570547
);
571548
}
@@ -603,15 +580,15 @@ private Optional<ConnectionTypeResponse> getConnectionType(
603580
ConnectionTypeResponse.class,
604581
DatabaseType.CONNECTION_TYPE
605582
);
606-
ConnectionTypeResponse response = result.getModel();
583+
ConnectionTypeResponse response = result.model();
607584
if (response == null) {
608585
return Optional.empty();
609586
}
610587
return Optional.of(
611588
new ConnectionTypeResponse(
612589
response,
613-
result.getIpAddress(),
614-
result.getNetwork()
590+
result.ipAddress(),
591+
result.network()
615592
)
616593
);
617594
}
@@ -649,15 +626,15 @@ private Optional<DomainResponse> getDomain(
649626
DomainResponse.class,
650627
DatabaseType.DOMAIN
651628
);
652-
DomainResponse response = result.getModel();
629+
DomainResponse response = result.model();
653630
if (response == null) {
654631
return Optional.empty();
655632
}
656633
return Optional.of(
657634
new DomainResponse(
658635
response,
659-
result.getIpAddress(),
660-
result.getNetwork()
636+
result.ipAddress(),
637+
result.network()
661638
)
662639
);
663640
}
@@ -695,15 +672,15 @@ private Optional<EnterpriseResponse> getEnterprise(
695672
EnterpriseResponse.class,
696673
DatabaseType.ENTERPRISE
697674
);
698-
EnterpriseResponse response = result.getModel();
675+
EnterpriseResponse response = result.model();
699676
if (response == null) {
700677
return Optional.empty();
701678
}
702679
return Optional.of(
703680
new EnterpriseResponse(
704681
response,
705-
result.getIpAddress(),
706-
result.getNetwork(),
682+
result.ipAddress(),
683+
result.network(),
707684
locales
708685
)
709686
);
@@ -742,15 +719,15 @@ private Optional<IspResponse> getIsp(
742719
IspResponse.class,
743720
DatabaseType.ISP
744721
);
745-
IspResponse response = result.getModel();
722+
IspResponse response = result.model();
746723
if (response == null) {
747724
return Optional.empty();
748725
}
749726
return Optional.of(
750727
new IspResponse(
751728
response,
752-
result.getIpAddress(),
753-
result.getNetwork()
729+
result.ipAddress(),
730+
result.network()
754731
)
755732
);
756733
}

src/main/java/com/maxmind/geoip2/WebServiceClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import java.net.http.HttpResponse;
2929
import java.nio.charset.StandardCharsets;
3030
import java.time.Duration;
31-
import java.util.ArrayList;
3231
import java.util.Base64;
33-
import java.util.Collections;
3432
import java.util.HashMap;
3533
import java.util.List;
3634
import java.util.Map;
@@ -177,7 +175,7 @@ public static final class Builder {
177175
Duration connectTimeout = null;
178176
Duration requestTimeout = Duration.ofSeconds(20);
179177

180-
List<String> locales = Collections.singletonList("en");
178+
List<String> locales = List.of("en");
181179
private ProxySelector proxy = null;
182180
private HttpClient httpClient = null;
183181

@@ -241,7 +239,7 @@ public WebServiceClient.Builder port(int val) {
241239
* @return Builder object
242240
*/
243241
public Builder locales(List<String> val) {
244-
this.locales = new ArrayList<>(val);
242+
this.locales = List.copyOf(val);
245243
return this;
246244
}
247245

src/main/java/com/maxmind/geoip2/model/ConnectionTypeResponse.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,14 @@ public static ConnectionType fromString(String s) {
5555
return null;
5656
}
5757

58-
switch (s) {
59-
case "Dialup":
60-
return ConnectionType.DIALUP;
61-
case "Cable/DSL":
62-
return ConnectionType.CABLE_DSL;
63-
case "Corporate":
64-
return ConnectionType.CORPORATE;
65-
case "Cellular":
66-
return ConnectionType.CELLULAR;
67-
case "Satellite":
68-
return ConnectionType.SATELLITE;
69-
default:
70-
return null;
71-
}
58+
return switch (s) {
59+
case "Dialup" -> ConnectionType.DIALUP;
60+
case "Cable/DSL" -> ConnectionType.CABLE_DSL;
61+
case "Corporate" -> ConnectionType.CORPORATE;
62+
case "Cellular" -> ConnectionType.CELLULAR;
63+
case "Satellite" -> ConnectionType.SATELLITE;
64+
default -> null;
65+
};
7266
}
7367
}
7468

0 commit comments

Comments
 (0)