Skip to content

Commit 98265c6

Browse files
oschwaldclaude
andcommitted
Deprecate get* methods in non-record classes
Public getter methods in non-record classes (DatabaseReader, exception classes) have been renamed to follow the same naming convention as records (e.g., metadata() instead of getMetadata()). The old getter methods are still available but have been deprecated and will be removed in version 6.0.0. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fc59422 commit 98265c6

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ CHANGELOG
3737
* **BREAKING:** Removed no longer necessary `JacksonInject` annotations for
3838
`ip_address`, `network`, and `traits` from several classes. The
3939
`JsonInjector` class was removed.
40+
* Public getter methods in non-record classes (e.g., `DatabaseReader`,
41+
exception classes) have been renamed to follow the same naming convention as
42+
records (e.g., `metadata()` instead of `getMetadata()`). The old getter
43+
methods are still available but have been deprecated and will be removed in
44+
version 6.0.0.
4045

4146
4.4.0 (2025-08-28)
4247
------------------

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private DatabaseReader(Builder builder) throws IOException {
115115
}
116116

117117
private int getDatabaseType() {
118-
String databaseType = this.getMetadata().getDatabaseType();
118+
String databaseType = this.metadata().getDatabaseType();
119119
int type = 0;
120120
if (databaseType.contains("GeoIP2-Anonymous-IP")) {
121121
type |= DatabaseType.ANONYMOUS_IP.type;
@@ -255,7 +255,7 @@ private <T> LookupResult<T> get(InetAddress ipAddress, Class<T> cls,
255255
String caller = Thread.currentThread().getStackTrace()[3]
256256
.getMethodName();
257257
throw new UnsupportedOperationException(
258-
"Invalid attempt to open a " + getMetadata().getDatabaseType()
258+
"Invalid attempt to open a " + metadata().getDatabaseType()
259259
+ " database using the " + caller + " method");
260260
}
261261

@@ -735,7 +735,16 @@ private Optional<IspResponse> getIsp(
735735
/**
736736
* @return the metadata for the open MaxMind DB file.
737737
*/
738-
public Metadata getMetadata() {
738+
public Metadata metadata() {
739739
return this.reader.getMetadata();
740740
}
741+
742+
/**
743+
* @return the metadata for the open MaxMind DB file.
744+
* @deprecated Use {@link #metadata()} instead. This method will be removed in 6.0.0.
745+
*/
746+
@Deprecated(since = "5.0.0", forRemoval = true)
747+
public Metadata getMetadata() {
748+
return metadata();
749+
}
741750
}

src/main/java/com/maxmind/geoip2/exception/HttpException.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,34 @@ public HttpException(String message, int httpStatus, URI uri,
3939
/**
4040
* @return the HTTP status of the query that caused the exception.
4141
*/
42-
public int getHttpStatus() {
42+
public int httpStatus() {
4343
return this.httpStatus;
4444
}
4545

46+
/**
47+
* @return the HTTP status of the query that caused the exception.
48+
* @deprecated Use {@link #httpStatus()} instead. This method will be removed in 6.0.0.
49+
*/
50+
@Deprecated(since = "5.0.0", forRemoval = true)
51+
public int getHttpStatus() {
52+
return httpStatus();
53+
}
54+
4655
/**
4756
* @return the URI queried.
4857
*/
49-
public URI getUri() {
58+
public URI uri() {
5059
return this.uri;
5160
}
5261

62+
/**
63+
* @return the URI queried.
64+
* @deprecated Use {@link #uri()} instead. This method will be removed in 6.0.0.
65+
*/
66+
@Deprecated(since = "5.0.0", forRemoval = true)
67+
public URI getUri() {
68+
return uri();
69+
}
70+
5371

5472
}

src/main/java/com/maxmind/geoip2/exception/InvalidRequestException.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,33 @@ public InvalidRequestException(String message, String code, int httpStatus,
3939
/**
4040
* @return The error code returned by the MaxMind web service.
4141
*/
42-
public String getCode() {
42+
public String code() {
4343
return this.code;
4444
}
4545

46+
/**
47+
* @return The error code returned by the MaxMind web service.
48+
* @deprecated Use {@link #code()} instead. This method will be removed in 6.0.0.
49+
*/
50+
@Deprecated(since = "5.0.0", forRemoval = true)
51+
public String getCode() {
52+
return code();
53+
}
54+
4655
/**
4756
* @return the URI queried.
4857
*/
49-
public URI getUri() {
58+
public URI uri() {
5059
return this.uri;
5160
}
5261

62+
/**
63+
* @return the URI queried.
64+
* @deprecated Use {@link #uri()} instead. This method will be removed in 6.0.0.
65+
*/
66+
@Deprecated(since = "5.0.0", forRemoval = true)
67+
public URI getUri() {
68+
return uri();
69+
}
70+
5371
}

0 commit comments

Comments
 (0)