-
Notifications
You must be signed in to change notification settings - Fork 784
Closed
Description
Describe the bug
For example the following DB connection URIs fail:
- jdbc:sqlserver://host:port;databaseName=aDatabaseName;instanceName=anInstance;
- jdbc:sqlserver://host\anInstance:port;databaseName=aDatabaseName;
Root Cause
URI.create(..)throws exception as the above URIs are not a valid RFC 2396 URI, due to the\before the instance definition.
private void parseAndSetServerIpAndPort(ConnectionInfo connectionInfo, Connection connection,
String dataSourceName) {
URI url = null;
String remoteServiceName = "";
try {
String urlAsString = connection.getMetaData().getURL().substring(5);
url = URI.create(urlAsString.replace(" ", ""));
...
catch (Exception e) {
// remote address is optional
}
connectionInfo.url = url;
...
- Although parseAndSetServerIpAndPort() mentions that successful parsing is optional and sets
urlto null, then later on there is an unguarded access that throws the null pointer exception.
connectionSpan.getSpan().remoteIpAndPort(connectionInfo.url.getHost(), connectionInfo.url.getPort());
I thinks point (2) is obvious and no code to reproduce the issue is required.
Exception
Caused by: java.lang.NullPointerException: null
at org.springframework.cloud.sleuth.instrument.jdbc.TraceListenerStrategy.afterGetConnection(TraceListenerStrategy.java:135) ~[spring-cloud-sleuth-instrumentation-3.1.2.jar:3.1.2]
at org.springframework.cloud.sleuth.instrument.jdbc.TraceJdbcEventListener.onAfterGetConnection(TraceJdbcEventListener.java:72) ~[spring-cloud-sleuth-instrumentation-3.1.2.jar:3.1.2]
at com.p6spy.engine.event.CompoundJdbcEventListener.onAfterGetConnection(CompoundJdbcEventListener.java:81) ~[p6spy-3.9.1.jar:na]
at com.p6spy.engine.spy.P6DataSource.getConnection(P6DataSource.java:306) ~[p6spy-3.9.1.jar:na]
at org.springframework.jdbc.datasource.DelegatingDataSource.getConnection(DelegatingDataSource.java:99) ~[spring-jdbc-5.3.20.jar:5.3.20]
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:267) ~[liquibase-core-4.0.0.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.20.jar:5.3.20]
... 18 common frames omitted