Skip to content

Commit cf6bd1b

Browse files
committed
[#2478] Terrible error reporting when JDBC scheme is not recognized
1 parent f2e7ec0 commit cf6bd1b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/DefaultSqlClientPoolConfiguration.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,16 @@ public PoolOptions poolOptions() {
9090

9191
@Override
9292
public SqlConnectOptions connectOptions(URI uri) {
93-
String scheme = uri.getScheme();
94-
String path = scheme.equals( "oracle" )
93+
final String scheme = uri.getScheme();
94+
if ( !isSchemeSupported( scheme ) ) {
95+
throw new IllegalArgumentException( "Unsupported URI scheme: " + scheme );
96+
}
97+
98+
final String path = scheme.equals( "oracle" )
9599
? oraclePath( uri )
96100
: uri.getPath();
97101

98-
String database = path.length() > 0
102+
String database = path != null && !path.isEmpty()
99103
? path.substring( 1 )
100104
: "";
101105

@@ -105,8 +109,8 @@ public SqlConnectOptions connectOptions(URI uri) {
105109
database = database.substring( 0, database.indexOf( ':' ) );
106110
}
107111

108-
String host = findHost( uri, scheme );
109-
int port = findPort( uri, scheme );
112+
final String host = findHost( uri, scheme );
113+
final int port = findPort( uri, scheme );
110114

111115
//see if the credentials were specified via properties
112116
String username = user;
@@ -385,4 +389,11 @@ private int defaultPort(String scheme) {
385389
}
386390
}
387391

392+
private boolean isSchemeSupported(String scheme) {
393+
return switch ( scheme ) {
394+
case "postgresql", "postgres", "mariadb", "mysql", "db2", "cockroachdb", "sqlserver", "oracle" -> true;
395+
default -> false;
396+
};
397+
}
398+
388399
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/provider/service/NoJdbcEnvironmentInitiator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static java.lang.Integer.parseInt;
3030
import static java.util.Objects.requireNonNullElse;
3131
import static java.util.function.Function.identity;
32+
import static org.hibernate.cfg.JdbcSettings.ALLOW_METADATA_ON_BOOT;
3233
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
3334

3435
/**
@@ -84,7 +85,7 @@ protected JdbcEnvironmentImpl getJdbcEnvironmentUsingJdbcMetadata(
8485
Integer explicitDatabaseMajorVersion,
8586
Integer explicitDatabaseMinorVersion,
8687
String explicitDatabaseVersion) {
87-
try {
88+
if ( configurationValues.containsKey( ALLOW_METADATA_ON_BOOT ) ) {
8889
final Dialect dialect = new DialectBuilder( configurationValues, registry )
8990
.build(
9091
dialectFactory,
@@ -97,7 +98,7 @@ protected JdbcEnvironmentImpl getJdbcEnvironmentUsingJdbcMetadata(
9798
);
9899
return new JdbcEnvironmentImpl( registry, dialect );
99100
}
100-
catch (RuntimeException e) {
101+
else {
101102
return getJdbcEnvironmentWithDefaults( configurationValues, registry, dialectFactory );
102103
}
103104
}

0 commit comments

Comments
 (0)