Bug #85223 MysqlSQLXML setString crash
Submitted: 28 Feb 2017 10:47 Modified: 2 Mar 2017 7:20
Reporter: Yordan Gigov Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:all OS:Any
Assigned to: CPU Architecture:Any
Tags: NullPointerException, sqlxml

[28 Feb 2017 10:47] Yordan Gigov
Description:
SQLXML parameter binding does not work if source is a String.

How to repeat:
Create any prepared statement over JDBC that takes an XML data type.
SQLXML sqlxml = connection.createSQLXML();
sqlxml.setString(stringifiedDocument); //on the SQLXML object.
statement.setSQLXML(index, sqlxml);
crash and burn.

Suggested fix:
Inside MysqlSQLXML.serializeAsCharacterStream remove the workingWithResult check.
The null-checks are sufficient for each possible input type.
[28 Feb 2017 12:16] Chiranjeevi Battula
Hello Yordan Gigov,

Thank you for the bug report.
Could you please provide repeatable test case (exact steps, sample test case, full stack trace  etc. - please make it as private if you prefer) to confirm this issue at our end?

Thanks,
Chiranjeevi.
[28 Feb 2017 16:09] Yordan Gigov
Test case

Attachment: jdbc-test.zip (application/zip, text), 10.46 KiB.

[28 Feb 2017 16:13] Yordan Gigov
Added test case. Change pom.xml dependency version to 6.0.5 to confirm for 6.0 branch.

Change line 25 of the test to `xml.setCharacterStream().write(elementString);` and it works. Direct string source is the one it doesn't handle correctly.
[2 Mar 2017 7:20] Chiranjeevi Battula
Hello Yordan Gigov,

Thank you for the feedback and test case.
verified as described.

Thanks,
Chiranjeevi.
[2 Mar 2017 7:21] Chiranjeevi Battula
Stack Tace:

java.lang.NullPointerException
	at com.mysql.jdbc.JDBC4MysqlSQLXML.serializeAsCharacterStream(JDBC4MysqlSQLXML.java:588)
	at com.mysql.jdbc.JDBC4PreparedStatementHelper.setSQLXML(JDBC4PreparedStatementHelper.java:93)
	at com.mysql.jdbc.JDBC4PreparedStatement.setSQLXML(JDBC4PreparedStatement.java:72)
	at com.mysql.jdbc.test.SqlTest.runtest(SqlTest.java:27)
	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:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
	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:498)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
	at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)