Bug #58232 CallableStatement fails to fetch OUT parameter against 5.5 server
Submitted: 16 Nov 2010 16:08 Modified: 26 Nov 2010 11:32
Reporter: Tonci Grgin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version: OS:Any
Assigned to: Tony Bedford CPU Architecture:Any
Tags: regression

[16 Nov 2010 16:08] Tonci Grgin
Description:
testBug10310 in CallableStatementRegression test suite fails due to fact that OUT parameter in I__S.PARAMETERS table has no name (COLUMN_NAME: NULL) which is a correct server behavior according to http://dev.mysql.com/doc/refman/5.5/en/parameters-table.html.

How to repeat:
Run said test against newer server:
java.lang.NullPointerException
	at com.mysql.jdbc.CallableStatement.retrieveOutParams(CallableStatement.java:1964)
	at com.mysql.jdbc.CallableStatement.execute(CallableStatement.java:915)
	at testsuite.regression.CallableStatementRegressionTest.testBug10310(CallableStatementRegressionTest.java:518)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Suggested fix:
Fix code so that CallableStatement.retrieveOutParams 
if (!outParameterName.startsWith("@")) {
does not NPE.
[19 Nov 2010 10:30] Tonci Grgin
Pushed up to revision 1006.

Explanation: c/J is using user variables to fetch result of stored function. OUT parameter name is "mangled" to ensure it does not collide with other user variables/parameter names (i.e. @com_mysql_jdbc_outparam_). Problem arises for RETURN values when their description is fetched from I__S (http://dev.mysql.com/doc/refman/5.5/en/parameters-table.html) as PARAMETER_NAME is NULL thus the NPE. Fix is in that visibility of DataBaseMetaDataUsingInfoSchema.hasParametersView has changed and "getter" was added. This is then used in CallableStatement to check if MySQL server has I__S.PARAMETERS table and handle null paramname correctly.
[26 Nov 2010 11:32] Tony Bedford
An entry has been added to the 5.1.14 changelog:

The CallableStatementRegression test suite failed with a Null Pointer Exception because the OUT parameter in the I__S.PARAMETERS table had no name, that is COLUMN_NAME had the value NULL.