Skip to content

Clean up Maria DB parsing logic warnings #7617

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

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog.trace.bootstrap.instrumentation.jdbc;

import static datadog.trace.bootstrap.instrumentation.jdbc.DBInfo.DEFAULT;
import static java.lang.Math.max;

import datadog.trace.api.Pair;
import datadog.trace.api.cache.DDCache;
Expand Down Expand Up @@ -201,7 +202,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
hostEndLoc = portLoc;
try {
builder.port(Integer.parseInt(jdbcUrl.substring(portLoc + 1, dbLoc)));
} catch (final NumberFormatException e) {
} catch (final NumberFormatException ignored) {
}
} else {
hostEndLoc = dbLoc;
Expand All @@ -224,10 +225,11 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
}
final int hostEndLoc;
final int clusterSepLoc = jdbcUrl.indexOf(',');
final int ipv6End = jdbcUrl.startsWith("[") ? jdbcUrl.indexOf(']') : -1;
int portLoc = jdbcUrl.indexOf(':', Math.max(0, ipv6End));
portLoc = clusterSepLoc < portLoc ? -1 : portLoc;
final int dbLoc = jdbcUrl.indexOf('/', Math.max(portLoc, clusterSepLoc));
final int ipv6End =
!jdbcUrl.isEmpty() && jdbcUrl.charAt(0) == '[' ? jdbcUrl.indexOf(']') : -1;
int portLoc = jdbcUrl.indexOf(':', max(0, ipv6End));
portLoc = -1 < clusterSepLoc && clusterSepLoc < portLoc ? -1 : portLoc;
final int dbLoc = jdbcUrl.indexOf('/', max(portLoc, clusterSepLoc));

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

Expand All @@ -247,7 +249,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
final int portEndLoc = clusterSepLoc > 0 ? clusterSepLoc : dbLoc;
try {
builder.port(Integer.parseInt(jdbcUrl.substring(portLoc + 1, portEndLoc)));
} catch (final NumberFormatException e) {
} catch (final NumberFormatException ignored) {
}
} else {
hostEndLoc = clusterSepLoc > 0 ? clusterSepLoc : dbLoc;
Expand Down Expand Up @@ -390,7 +392,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
Integer parsedPort = null;
try {
parsedPort = Integer.parseInt(portOrInstance);
} catch (final NumberFormatException e) {
} catch (final NumberFormatException ignored) {
}
if (parsedPort == null) {
port = null;
Expand Down Expand Up @@ -566,7 +568,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {

@Override
DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
String instance = null;
String instance;
final DBInfo dbInfo = builder.build();
if (dbInfo.getUser() == null) {
builder.user(DEFAULT_USER);
Expand Down Expand Up @@ -680,9 +682,8 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
}
} else {
builder.subtype("directory");
final String urlInstance = details;
if (!urlInstance.isEmpty()) {
instance = urlInstance;
if (!details.isEmpty()) {
instance = details;
}
}

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

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

Expand Down Expand Up @@ -741,7 +741,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
hostEndLoc = portLoc;
try {
builder.port(Integer.parseInt(details.substring(portLoc + 1, dbLoc)));
} catch (final NumberFormatException e) {
} catch (final NumberFormatException ignored) {
}
} else if (dbLoc > 0) {
hostEndLoc = dbLoc;
Expand Down