-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat unsupported URLs as specified in Driver#connect to avoid overwr…
…iting the "real" exception (#115) * Treat unsupported URLs as specified in `Driver#connect` to avoid overwriting the "real" exception * Drop documentation on URL being changed * - FIX: connect() method modification to retain "mangled" url for connection - FIX: acceptsURL() method rework to avoid potentially invoking super method with null param Signed-off-by: Phillip Ross <[email protected]> --------- Signed-off-by: Phillip Ross <[email protected]> Co-authored-by: Phillip Ross <[email protected]>
- Loading branch information
1 parent
f6ac473
commit c2284e7
Showing
5 changed files
with
71 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
postgis-jdbc/src/test/java/net/postgis/jdbc/DriverConnectBehaviorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.postgis.jdbc; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
public class DriverConnectBehaviorTest { | ||
|
||
@Test | ||
public void testThatPostGisDoesNotOverwriteSavedExceptionForUnsupportedConnectionString() { | ||
try { | ||
DriverManager.getConnection("jdbc:missing"); | ||
} catch (SQLException e) { | ||
// This should not be "Unknown protocol or subprotocol in url jdbc:missing", which | ||
// would indicate that PostGIS threw an exception instead of returning `null` from | ||
// the `connect` method for an unsupported connection string. | ||
// (This is documented in `java.sql.Driver.connect`.) | ||
// | ||
// The former behavior is not desirable as throwing an exception causes a previously | ||
// saved exception from a "better fitting" driver to be overwritten by PostGis, despite | ||
// PostGis not actually being able to handle the connection. | ||
// | ||
// (Imagine an Oracle connection string with a wrong password, in which the Oracle | ||
// driver's exception regarding the wrong password would be replaced with a generic | ||
// nonsensical PostGis exception.) | ||
Assert.assertEquals("No suitable driver found for jdbc:missing", e.getMessage()); | ||
} | ||
} | ||
|
||
} |