Description:
when i'am using Connector/J 5.1.46 loadblance mode,but it produce an NullPointerException.
How to repeat:
1. jdbc url is "jdbc:mysql:loadbalance://127.0.0.1:5061,127.0.0.1:5062,127.0.0.1:5063/base?loadBalanceAutoCommitStatementThreshold=3"
2.code like:
Connection connection=druid.getConnection();
JdbcUtils.executeQuery(connection,"select * from customer",new ArrayList<Object>())
JdbcUtils.close(connection);
3.error info
Exception in thread "main" java.sql.SQLException: Unexpected exception encountered during query.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2523)
at com.mysql.jdbc.MultiHostMySQLConnection.execSQL(MultiHostMySQLConnection.java:158)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.mysql.jdbc.MultiHostConnectionProxy$JdbcInterfaceProxy.invoke(MultiHostConnectionProxy.java:108)
at com.sun.proxy.$Proxy17.executeQuery(Unknown Source)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:228)
at com.alibaba.druid.util.JdbcUtils.executeQuery(JdbcUtils.java:695)
at pool.Test.main(Test.java:32)
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.StringUtils.startsWithIgnoreCase(StringUtils.java:1485)
at com.mysql.jdbc.StringUtils.startsWithIgnoreCase(StringUtils.java:1500)
at com.mysql.jdbc.LoadBalancedAutoCommitInterceptor.postProcess(LoadBalancedAutoCommitInterceptor.java:79)
at com.mysql.jdbc.MysqlIO.invokeStatementInterceptorsPost(MysqlIO.java:2888)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2811)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
... 12 more
Suggested fix:
line 79 in com.mysql.jdbc.LoadBalancedAutoCommitInterceptor
code " if (!this.countStatements || StringUtils.startsWithIgnoreCase(sql, "SET") || StringUtils.startsWithIgnoreCase(sql, "SHOW")) {"
shoud add "sql!=null" :
"if (!this.countStatements || (sql!=null&&StringUtils.startsWithIgnoreCase(sql, "SET")) || (sql!=null&&StringUtils.startsWithIgnoreCase(sql, "SHOW")) {"