Skip to content

Commit 5218189

Browse files
oschwaldclaude
andcommitted
Seal GeoIp2Exception hierarchy
Make GeoIp2Exception a sealed class with an explicit permits clause listing all allowed subclasses. This provides: - Explicit API stability guarantees - new exception types cannot be added externally - Compiler-enforced exhaustiveness checking for pattern matching in future Java versions - Clear documentation of the complete exception hierarchy All subclasses (AddressNotFoundException, AuthenticationException, InvalidRequestException, OutOfQueriesException, and PermissionRequiredException) were already marked as final, making them compatible with the sealed parent. Note: HttpException extends IOException, not GeoIp2Exception, so it remains outside this sealed hierarchy. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 79e3d9c commit 5218189

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
* This class represents a generic GeoIP2 error. All other exceptions thrown by
55
* the GeoIP2 API subclass this exception
66
*/
7-
public class GeoIp2Exception extends Exception {
7+
public sealed class GeoIp2Exception extends Exception
8+
permits AddressNotFoundException,
9+
AuthenticationException,
10+
InvalidRequestException,
11+
OutOfQueriesException,
12+
PermissionRequiredException {
813

914

1015
/**

0 commit comments

Comments
 (0)