Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
distribution: ['zulu']
os: [ubuntu-latest, windows-latest, macos-latest]
version: [ 11, 17, 21, 22 ]
version: [ 17, 21, 22, 23 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this list match the reader package? That one made more sense to me. If it changes, we should update the changelog too.

steps:
- uses: actions/checkout@v5
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ CHANGELOG
GeoIP2 Anonymous IP database for anonymous proxy detection instead.
* **BREAKING:** The deprecated `Location.getMetroCode()` method has been
removed. Metro code values are no longer maintained.
* **BREAKING:** Java 11 support has been dropped. Java 17 or later is now required.
* Updated project to use Java 17 language features including switch expressions
and modern collection factories.
* Updated GitHub Actions workflow to test on Java 17, 21, 22, and 23.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged it already, but I wonder if we'd want to mention the above 2 points in the reader changelog too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I am not sure. I generally leave off internal-only changes that don't impact users, but Claude added these and I guess I didn't object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them, but I am happy to add them to all three if you think they are helpful.


4.4.0 (2025-08-28)
------------------
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
https://maxmind.github.io/MaxMind-DB-Reader-java/doc/latest/
</link>
</links>
<source>11</source>
<source>17</source>
<doclint>-missing</doclint>
</configuration>
<executions>
Expand Down Expand Up @@ -198,8 +198,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<release>11</release>
<source>11</source>
<release>17</release>
<source>17</source>
<target>11</target>
</configuration>
</plugin>
Expand Down
91 changes: 34 additions & 57 deletions src/main/java/com/maxmind/geoip2/DatabaseReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -150,9 +149,8 @@ private int getDatabaseType() {
type |= DatabaseType.ISP.type;
}
if (type == 0) {
// XXX - exception type
throw new UnsupportedOperationException(
"Invalid attempt to open an unknown database type: " + databaseType);
throw new IllegalArgumentException(
"Unsupported database type: " + databaseType);
}
return type;
}
Expand All @@ -174,7 +172,7 @@ public static final class Builder {
final File database;
final InputStream stream;

List<String> locales = Collections.singletonList("en");
List<String> locales = List.of("en");
FileMode mode = FileMode.MEMORY_MAPPED;
NodeCache cache = NoCache.getInstance();

Expand Down Expand Up @@ -239,28 +237,7 @@ public DatabaseReader build() throws IOException {
}
}

static final class LookupResult<T> {
final T model;
final String ipAddress;
final Network network;

LookupResult(T model, String ipAddress, Network network) {
this.model = model;
this.ipAddress = ipAddress;
this.network = network;
}

T getModel() {
return this.model;
}

String getIpAddress() {
return this.ipAddress;
}

Network getNetwork() {
return this.network;
}
static record LookupResult<T>(T model, String ipAddress, Network network) {
}

/**
Expand Down Expand Up @@ -333,15 +310,15 @@ private Optional<CountryResponse> getCountry(
CountryResponse.class,
DatabaseType.COUNTRY
);
CountryResponse response = result.getModel();
CountryResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new CountryResponse(
response,
result.getIpAddress(),
result.getNetwork(),
result.ipAddress(),
result.network(),
locales
)
);
Expand Down Expand Up @@ -372,15 +349,15 @@ private Optional<CityResponse> getCity(
CityResponse.class,
DatabaseType.CITY
);
CityResponse response = result.getModel();
CityResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new CityResponse(
response,
result.getIpAddress(),
result.getNetwork(),
result.ipAddress(),
result.network(),
locales
)
);
Expand Down Expand Up @@ -419,15 +396,15 @@ private Optional<AnonymousIpResponse> getAnonymousIp(
AnonymousIpResponse.class,
DatabaseType.ANONYMOUS_IP
);
AnonymousIpResponse response = result.getModel();
AnonymousIpResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new AnonymousIpResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down Expand Up @@ -466,15 +443,15 @@ private Optional<AnonymousPlusResponse> getAnonymousPlus(
AnonymousPlusResponse.class,
DatabaseType.ANONYMOUS_PLUS
);
AnonymousPlusResponse response = result.getModel();
AnonymousPlusResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new AnonymousPlusResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down Expand Up @@ -512,15 +489,15 @@ private Optional<IpRiskResponse> getIpRisk(InetAddress ipAddress) throws IOExcep
IpRiskResponse.class,
DatabaseType.IP_RISK
);
IpRiskResponse response = result.getModel();
IpRiskResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new IpRiskResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down Expand Up @@ -557,15 +534,15 @@ private Optional<AsnResponse> getAsn(InetAddress ipAddress)
AsnResponse.class,
DatabaseType.ASN
);
AsnResponse response = result.getModel();
AsnResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new AsnResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down Expand Up @@ -603,15 +580,15 @@ private Optional<ConnectionTypeResponse> getConnectionType(
ConnectionTypeResponse.class,
DatabaseType.CONNECTION_TYPE
);
ConnectionTypeResponse response = result.getModel();
ConnectionTypeResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new ConnectionTypeResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down Expand Up @@ -649,15 +626,15 @@ private Optional<DomainResponse> getDomain(
DomainResponse.class,
DatabaseType.DOMAIN
);
DomainResponse response = result.getModel();
DomainResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new DomainResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down Expand Up @@ -695,15 +672,15 @@ private Optional<EnterpriseResponse> getEnterprise(
EnterpriseResponse.class,
DatabaseType.ENTERPRISE
);
EnterpriseResponse response = result.getModel();
EnterpriseResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new EnterpriseResponse(
response,
result.getIpAddress(),
result.getNetwork(),
result.ipAddress(),
result.network(),
locales
)
);
Expand Down Expand Up @@ -742,15 +719,15 @@ private Optional<IspResponse> getIsp(
IspResponse.class,
DatabaseType.ISP
);
IspResponse response = result.getModel();
IspResponse response = result.model();
if (response == null) {
return Optional.empty();
}
return Optional.of(
new IspResponse(
response,
result.getIpAddress(),
result.getNetwork()
result.ipAddress(),
result.network()
)
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/maxmind/geoip2/WebServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -177,7 +175,7 @@ public static final class Builder {
Duration connectTimeout = null;
Duration requestTimeout = Duration.ofSeconds(20);

List<String> locales = Collections.singletonList("en");
List<String> locales = List.of("en");
private ProxySelector proxy = null;
private HttpClient httpClient = null;

Expand Down Expand Up @@ -241,7 +239,7 @@ public WebServiceClient.Builder port(int val) {
* @return Builder object
*/
public Builder locales(List<String> val) {
this.locales = new ArrayList<>(val);
this.locales = List.copyOf(val);
return this;
}

Expand Down
22 changes: 8 additions & 14 deletions src/main/java/com/maxmind/geoip2/model/ConnectionTypeResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,14 @@ public static ConnectionType fromString(String s) {
return null;
}

switch (s) {
case "Dialup":
return ConnectionType.DIALUP;
case "Cable/DSL":
return ConnectionType.CABLE_DSL;
case "Corporate":
return ConnectionType.CORPORATE;
case "Cellular":
return ConnectionType.CELLULAR;
case "Satellite":
return ConnectionType.SATELLITE;
default:
return null;
}
return switch (s) {
case "Dialup" -> ConnectionType.DIALUP;
case "Cable/DSL" -> ConnectionType.CABLE_DSL;
case "Corporate" -> ConnectionType.CORPORATE;
case "Cellular" -> ConnectionType.CELLULAR;
case "Satellite" -> ConnectionType.SATELLITE;
default -> null;
};
}
}

Expand Down