Skip to content

Commit e11c39e

Browse files
feat(jdbc): Clean up logic warnings (#7617)
1 parent 8f1e767 commit e11c39e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.bootstrap.instrumentation.jdbc;
22

33
import static datadog.trace.bootstrap.instrumentation.jdbc.DBInfo.DEFAULT;
4+
import static java.lang.Math.max;
45

56
import datadog.trace.api.Pair;
67
import datadog.trace.api.cache.DDCache;
@@ -201,7 +202,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
201202
hostEndLoc = portLoc;
202203
try {
203204
builder.port(Integer.parseInt(jdbcUrl.substring(portLoc + 1, dbLoc)));
204-
} catch (final NumberFormatException e) {
205+
} catch (final NumberFormatException ignored) {
205206
}
206207
} else {
207208
hostEndLoc = dbLoc;
@@ -224,10 +225,11 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
224225
}
225226
final int hostEndLoc;
226227
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));
231233

232234
final int paramLoc = jdbcUrl.indexOf('?', dbLoc);
233235

@@ -247,7 +249,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
247249
final int portEndLoc = clusterSepLoc > 0 ? clusterSepLoc : dbLoc;
248250
try {
249251
builder.port(Integer.parseInt(jdbcUrl.substring(portLoc + 1, portEndLoc)));
250-
} catch (final NumberFormatException e) {
252+
} catch (final NumberFormatException ignored) {
251253
}
252254
} else {
253255
hostEndLoc = clusterSepLoc > 0 ? clusterSepLoc : dbLoc;
@@ -390,7 +392,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
390392
Integer parsedPort = null;
391393
try {
392394
parsedPort = Integer.parseInt(portOrInstance);
393-
} catch (final NumberFormatException e) {
395+
} catch (final NumberFormatException ignored) {
394396
}
395397
if (parsedPort == null) {
396398
port = null;
@@ -566,7 +568,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
566568

567569
@Override
568570
DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
569-
String instance = null;
571+
String instance;
570572
final DBInfo dbInfo = builder.build();
571573
if (dbInfo.getUser() == null) {
572574
builder.user(DEFAULT_USER);
@@ -680,9 +682,8 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
680682
}
681683
} else {
682684
builder.subtype("directory");
683-
final String urlInstance = details;
684-
if (!urlInstance.isEmpty()) {
685-
instance = urlInstance;
685+
if (!details.isEmpty()) {
686+
instance = details;
686687
}
687688
}
688689

@@ -695,7 +696,6 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
695696

696697
/** http://jtds.sourceforge.net/faq.html#urlFormat */
697698
JTDS("jtds") {
698-
private static final String DEFAULT_HOST = "localhost";
699699
private static final int DEFAULT_SQL_SERVER_PORT = 1433;
700700
private static final int DEFAULT_SYBASE_PORT = 7100;
701701

@@ -741,7 +741,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
741741
hostEndLoc = portLoc;
742742
try {
743743
builder.port(Integer.parseInt(details.substring(portLoc + 1, dbLoc)));
744-
} catch (final NumberFormatException e) {
744+
} catch (final NumberFormatException ignored) {
745745
}
746746
} else if (dbLoc > 0) {
747747
hostEndLoc = dbLoc;

0 commit comments

Comments
 (0)