1
1
package datadog .trace .bootstrap .instrumentation .jdbc ;
2
2
3
3
import static datadog .trace .bootstrap .instrumentation .jdbc .DBInfo .DEFAULT ;
4
+ import static java .lang .Math .max ;
4
5
5
6
import datadog .trace .api .Pair ;
6
7
import datadog .trace .api .cache .DDCache ;
@@ -201,7 +202,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
201
202
hostEndLoc = portLoc ;
202
203
try {
203
204
builder .port (Integer .parseInt (jdbcUrl .substring (portLoc + 1 , dbLoc )));
204
- } catch (final NumberFormatException e ) {
205
+ } catch (final NumberFormatException ignored ) {
205
206
}
206
207
} else {
207
208
hostEndLoc = dbLoc ;
@@ -224,10 +225,11 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
224
225
}
225
226
final int hostEndLoc ;
226
227
final int clusterSepLoc = jdbcUrl .indexOf (',' );
227
- final int ipv6End = jdbcUrl .startsWith ("[" ) ? jdbcUrl .indexOf (']' ) : -1 ;
228
- int portLoc = jdbcUrl .indexOf (':' , Math .max (0 , ipv6End ));
229
- portLoc = clusterSepLoc < portLoc ? -1 : portLoc ;
230
- final int dbLoc = jdbcUrl .indexOf ('/' , Math .max (portLoc , clusterSepLoc ));
228
+ final int ipv6End =
229
+ !jdbcUrl .isEmpty () && jdbcUrl .charAt (0 ) == '[' ? jdbcUrl .indexOf (']' ) : -1 ;
230
+ int portLoc = jdbcUrl .indexOf (':' , max (0 , ipv6End ));
231
+ portLoc = -1 < clusterSepLoc && clusterSepLoc < portLoc ? -1 : portLoc ;
232
+ final int dbLoc = jdbcUrl .indexOf ('/' , max (portLoc , clusterSepLoc ));
231
233
232
234
final int paramLoc = jdbcUrl .indexOf ('?' , dbLoc );
233
235
@@ -247,7 +249,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
247
249
final int portEndLoc = clusterSepLoc > 0 ? clusterSepLoc : dbLoc ;
248
250
try {
249
251
builder .port (Integer .parseInt (jdbcUrl .substring (portLoc + 1 , portEndLoc )));
250
- } catch (final NumberFormatException e ) {
252
+ } catch (final NumberFormatException ignored ) {
251
253
}
252
254
} else {
253
255
hostEndLoc = clusterSepLoc > 0 ? clusterSepLoc : dbLoc ;
@@ -390,7 +392,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
390
392
Integer parsedPort = null ;
391
393
try {
392
394
parsedPort = Integer .parseInt (portOrInstance );
393
- } catch (final NumberFormatException e ) {
395
+ } catch (final NumberFormatException ignored ) {
394
396
}
395
397
if (parsedPort == null ) {
396
398
port = null ;
@@ -566,7 +568,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
566
568
567
569
@ Override
568
570
DBInfo .Builder doParse (final String jdbcUrl , final DBInfo .Builder builder ) {
569
- String instance = null ;
571
+ String instance ;
570
572
final DBInfo dbInfo = builder .build ();
571
573
if (dbInfo .getUser () == null ) {
572
574
builder .user (DEFAULT_USER );
@@ -680,9 +682,8 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
680
682
}
681
683
} else {
682
684
builder .subtype ("directory" );
683
- final String urlInstance = details ;
684
- if (!urlInstance .isEmpty ()) {
685
- instance = urlInstance ;
685
+ if (!details .isEmpty ()) {
686
+ instance = details ;
686
687
}
687
688
}
688
689
@@ -695,7 +696,6 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
695
696
696
697
/** http://jtds.sourceforge.net/faq.html#urlFormat */
697
698
JTDS ("jtds" ) {
698
- private static final String DEFAULT_HOST = "localhost" ;
699
699
private static final int DEFAULT_SQL_SERVER_PORT = 1433 ;
700
700
private static final int DEFAULT_SYBASE_PORT = 7100 ;
701
701
@@ -741,7 +741,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
741
741
hostEndLoc = portLoc ;
742
742
try {
743
743
builder .port (Integer .parseInt (details .substring (portLoc + 1 , dbLoc )));
744
- } catch (final NumberFormatException e ) {
744
+ } catch (final NumberFormatException ignored ) {
745
745
}
746
746
} else if (dbLoc > 0 ) {
747
747
hostEndLoc = dbLoc ;
0 commit comments