quarkusio/quarkus · error · IllegalArgumentException
Invalid server address
Error message
Invalid server address
What it means
Quarkus parses each host in `hosts` into a MongoDB ServerAddress, splitting on ':' to allow host or host:port. If an entry splits into more than 2 segments (or is otherwise malformed), the parser rejects it with this IllegalArgumentException.
Source
Thrown at extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoClients.java:514
}
return addresses.stream()
.map(String::trim)
.map(new addressParser()).collect(Collectors.toList());
}
private static class addressParser implements Function<String, ServerAddress> {
@Override
public ServerAddress apply(String address) {
String[] segments = COLON_PATTERN.split(address);
if (segments.length == 1) {
// Host only, default port
return new ServerAddress(address);
} else if (segments.length == 2) {
// Host and port
return new ServerAddress(segments[0], Integer.parseInt(segments[1]));
} else {
throw new IllegalArgumentException("Invalid server address " + address);
}
}
}
private MongoCredential createMongoCredential(MongoClientConfig config) {
// get the authsource, or the database from the config, or 'admin' as it is the default auth source in mongo
// and null is not allowed
String authSource = config.credentials().authSource().orElse(config.database().orElse("admin"));
// AuthMechanism
AuthenticationMechanism mechanism = null;
Optional<String> maybeMechanism = config.credentials().authMechanism();
if (maybeMechanism.isPresent()) {
mechanism = getAuthenticationMechanism(maybeMechanism.get());
}
UsernamePassword usernamePassword = determineUserNamePassword(config.credentials());
if (usernamePassword == null) {View on GitHub (pinned to e1c734241f)
Solutions
- Use `host` or `host:port` per entry — put credentials/database in `connection-string` instead of `hosts`
- Wrap IPv6 addresses in brackets: `[::1]:27017`
- Remove stray commas/whitespace from the hosts list
- Prefer `quarkus.mongodb.connection-string` entirely for complex setups
Example fix
// before quarkus.mongodb.hosts=user:pass@mongo.example.com:27017 // after quarkus.mongodb.connection-string=mongodb://user:pass@mongo.example.com:27017
Defensive patterns
Strategy: validation
Validate before calling
// Validate hosts entries before use
for (String h : hosts.split(",")) {
String v = h.trim();
if (v.isEmpty()) throw new IllegalArgumentException("Empty host entry");
int colon = v.indexOf(':');
if (colon != v.lastIndexOf(':') && v.indexOf('[') < 0) {
throw new IllegalArgumentException("Malformed host (extra ':'): " + v);
}
if (colon >= 0 && Integer.parseInt(v.substring(colon + 1, v.indexOf(']') > 0 ? v.length() : v.length())) > 65535) {
throw new IllegalArgumentException("Invalid port: " + v);
}
} Prevention
- Never paste a full mongodb:// URI into the hosts property
- Wrap IPv6 literals in brackets
- Use connection-string for anything beyond plain host:port
When it happens
Trigger: Configuring `quarkus.mongodb.hosts` with a value like `host1:27017:extra`, an IPv6 literal without brackets, an empty host entry, or a full connection string pasted into the hosts property.
Common situations: Copying a `mongodb://user:pass@host:port/db` URI into the hosts field (the ':' in user:pass creates extra segments); writing bare IPv6 addresses like ::1 instead of [::1]:27017; trailing commas producing empty segments.
Related errors
- Invalid duration: ${value}
- Config property 'quarkus.mongodb.database' must be defined w
- <errorMessage>.formatted(clientName) (required Liquibase Mon
- Mongo client named '%s' not found
- Mongo Client '%s' is not active
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/99ce7f1922b4e84c.
Report an issue: GitHub.