Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DriverWrapper#mangleURL should return null (not throw an exception) ... #113

Closed
soc opened this issue Jan 21, 2022 · 5 comments
Closed

DriverWrapper#mangleURL should return null (not throw an exception) ... #113

soc opened this issue Jan 21, 2022 · 5 comments

Comments

@soc
Copy link
Contributor

soc commented Jan 21, 2022

... if the JDBC driver is not applicable to the connection string.

Offending code: https://github.com/postgis/postgis-java/blob/main/postgis-jdbc/src/main/java/net/postgis/jdbc/DriverWrapper.java#L265

Background:

If one has multiple JDBC driver registered, DriverManager.getConnection is called on each one of them until one driver declares it can handle the URL.

If that method throws an exception, then the "reason" is overwritten if multiple drivers are registered (e. g. Oracle, PostGis).

This causes an access attempt to an OracleDB with wrong password to return an Postgres error message.

This is because Oracle is tried and throws (correct, wrong password) and then Postgis can't handle it and also throws (not correct, should return null), thereby overwriting the exception and hiding the underlying problem:

java.sql.SQLException: Unknown protocol or subprotocol in url jdbc:oracle:thin:@oracle16.example.com:1521:oracle16
at net.postgis.jdbc.DriverWrapper.mangleURL(DriverWrapper.java:265)
at net.postgis.jdbc.DriverWrapper.connect(DriverWrapper.java:159)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:190)

If you agree with the assessment, would you accept a PR?

@AndreasWBartels
Copy link

part of the comment from Driver.connect()

 * Attempts to make a database connection to the given URL.
 * The driver should return "null" if it realizes it is the wrong kind
 * of driver to connect to the given URL.  This will be common, as when
 * the JDBC driver manager is asked to connect to a given URL it passes
 * the URL to each loaded driver in turn.

@phillipross
Copy link
Contributor

Thanks for identifying this issue! A PR to fix would be great. Would it also be possible to include a test that demonstrates the problem?

@soc
Copy link
Contributor Author

soc commented Jan 23, 2022

Mhhh, one could probable "fake" the drivers, register them, and make sure that the logic ends up as intended.

@phillipross yes, will do!

.... welp, but we probably would also need some database to connect to? :(

@soc
Copy link
Contributor Author

soc commented Jan 23, 2022

Nevermind, was easier than expected. #114

sebasbaumh added a commit to sebasbaumh/postgis-java-ng that referenced this issue Apr 26, 2022
@phillipross
Copy link
Contributor

PR #115 has been merged which I believe addresses this issue, so I'm going to close it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants