opentracing-contrib / java-jdbc

OpenTracing Instrumentation for JDBC
Apache License 2.0
82 stars 56 forks source link

URLParser not happy with tnsnames.ora logging 'error occurs when paring jdbc url' #35

Closed birdli66 closed 5 years ago

birdli66 commented 5 years ago

You have a small issue here in version 0.0.12 when using external tnsnames.ora wuth URL's of the from ''jdbc:oracle:thin:@tns_entry":

java.lang.StringIndexOutOfBoundsException: String index out of range: -2
    at java.lang.String.substring(String.java:1967)
    at io.opentracing.contrib.jdbc.parser.AbstractURLParser.fetchDatabaseHostsFromURL(AbstractURLParser.java:39)
    at io.opentracing.contrib.jdbc.parser.OracleURLParser.commonsURLParse(OracleURLParser.java:72)
    at io.opentracing.contrib.jdbc.parser.OracleURLParser.parse(OracleURLParser.java:67)

Details: https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/data-sources-and-URLs.html Section 8.2.6

Consequences: Minor

Fix in fetchDatabaseHostsFromURL:

        if (hostsLocation.startIndex() > hostsLocation.endIndex()) {
            final String unknownPortPostfix = ":0"; // need to load tnsnames.ora otherwise
            return url.substring(hostsLocation.startIndex()) + unknownPortPostfix;
        }

No big deal, but you might want to improve it.