Bug #91547 MySQL Connector/J 5.1.46 produce an NullPointerException
Submitted: 4 Jul 2018 12:27 Modified: 10 Jan 2022 9:44
Reporter: ge aa Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.46 OS:Any
Assigned to: CPU Architecture:Any

[4 Jul 2018 12:27] ge aa
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")) {"
[5 Jul 2018 12:25] Chiranjeevi Battula
Hello !!,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[10 Jan 2022 9:44] Alexander Soklakov
Posted by developer:
 
This bug does not exist in Connector/J 8.0.
Connector/J 5.1 series came to EOL on Feb 9th, 2021, see https://www.mysql.com/support/eol-notice.html, so this bug will not be fixed there.