Jody Grassel created OPENJPA-2195:
-------------------------------------
Summary: Native Query with specified result class can throw NPE
when return data contains a null-valued column
Key: OPENJPA-2195
URL: https://issues.apache.org/jira/browse/OPENJPA-2195
Project: OpenJPA
Issue Type: Bug
Components: kernel
Affects Versions: 2.2.0, 2.1.1, 2.1.0, 2.0.1, 2.0.0
Reporter: Jody Grassel
Assignee: Jody Grassel
When fetching a column from the current row in the ResultSet, there is the
potential for the value returned to be null (through nullable columns or SQL
aggregate functions such as MAX that can possible return a null value). If
there is no ResultPacker (such is the case when the query is created without a
result class type specified), this null value is stored in the EagerResultList
without any problem.
However, when a result class type is specified when the query is created, a
ResultPacker is instantiated and used to 'pack' each entry fetched from the
result set before saving it in the EagerResultList's internal List structure.
The problem is that the ResultPacker.pack(Object result) method is not
null-argument safe. The first thing the method attempts is try call getClass()
on its argument, which results in a NullPointerException in this situation:
java.lang.RuntimeException: <openjpa-2.0.2-SNAPSHOT-r422266:1334144M nonfatal
user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute
query "select NULLABLE_LNG_DATA FROM JAGNullField WHERE NFD_ID =?". Check the
query syntax for correctness. See nested exception for details.
at test.SimpleNullTest.test005(SimpleNullTest.java:152)
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:597)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: <openjpa-2.0.2-SNAPSHOT-r422266:1334144M nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Failed to execute query
"select NULLABLE_LNG_DATA FROM JAGNullField WHERE NFD_ID =?". Check the query
syntax for correctness. See nested exception for details.
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:870)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
at
org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
at test.SimpleNullTest.test005(SimpleNullTest.java:148)
... 25 more
Caused by: java.lang.NullPointerException
at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java:196)
at
org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(SQLProjectionResultObjectProvider.java:88)
at
org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1246)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
... 30 more
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira