OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.16k stars 597 forks source link

EclipseLink NullPointerException Cannot read field "index" because "key" is null #28078

Open njr-11 opened 7 months ago

njr-11 commented 7 months ago

Describe the bug

The JPQL query SELECT o FROM Account o WHERE (o.accountId=?1) fails when supplied with an AccountId that is an embeddable id for the entity.

EclipseLink converts this to SQL: SELECT BALANCE, BANKNAME, CHECKING, OWNER, ACCOUNTNUM, ROUTINGNUM FROM WLPAccount WHERE ((ACCOUNTNUM = ?) AND (ROUTINGNUM = ?)) which looks fine, but it gets an error processing the result: NullPointerException: Cannot read field "index" because "key" is null.

junit.framework.AssertionFailedError: 2024-04-03-11:04:47:525 ERROR: Caught exception attempting to call test method testLiteralDouble on servlet test.jakarta.data.jpa.web.DataJPATestServlet
jakarta.data.exceptions.DataException: jakarta.persistence.PersistenceException: java.lang.NullPointerException: Cannot read field "index" because "key" is null
at io.openliberty.data.internal.persistence.RepositoryImpl.failure(RepositoryImpl.java:607)
at io.openliberty.data.internal.persistence.RepositoryImpl.invoke(RepositoryImpl.java:2859)
at jdk.proxy11/jdk.proxy11.$Proxy100.findByAccountId(Unknown Source)
at test.jakarta.data.jpa.web.DataJPATestServlet.testLiteralDouble(DataJPATestServlet.java:2049)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at componenttest.app.FATServlet.doGet(FATServlet.java:73)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:527)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1260)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:748)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:445)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1361)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1077)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:77)
at com.ibm.ws.webcontainer40.servlet.CacheServletWrapper40.handleRequest(CacheServletWrapper40.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:969)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:293)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:1260)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:476)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:435)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:569)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:503)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:363)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:330)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:169)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:77)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:516)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:586)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:970)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1059)
at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:280)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:857)
Caused by: jakarta.persistence.PersistenceException: java.lang.NullPointerException: Cannot read field "index" because "key" is null
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:494)
at io.openliberty.data.internal.persistence.RepositoryImpl.invoke(RepositoryImpl.java:2570)
Caused by: java.lang.NullPointerException: Cannot read field "index" because "key" is null
at org.eclipse.persistence.internal.sessions.ArrayRecord.get(ArrayRecord.java:139)
at org.eclipse.persistence.descriptors.InheritancePolicy.classFromRow(InheritancePolicy.java:365)
at org.eclipse.persistence.mappings.AggregateObjectMapping.buildAggregateFromRow(AggregateObjectMapping.java:440)
at org.eclipse.persistence.mappings.AggregateObjectMapping.buildCloneFromRow(AggregateObjectMapping.java:786)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoWorkingCopyClone(ObjectBuilder.java:2111)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneFromRow(ObjectBuilder.java:2364)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:958)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInternal(ObjectBuilder.java:844)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:799)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:777)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:863)
at org.eclipse.persistence.queries.ReadObjectQuery.registerResultInUnitOfWork(ReadObjectQuery.java:896)
at org.eclipse.persistence.queries.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:570)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1236)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:913)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1195)
at org.eclipse.persistence.queries.ReadObjectQuery.execute(ReadObjectQuery.java:448)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1283)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:3025)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1841)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1823)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1788)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:263)
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:475) 

Steps to Reproduce
Uncomment these lines of code and run the test:

https://github.com/OpenLiberty/open-liberty/blob/8fdfcb7f06624d098f4170de68f1bb926e90ae8b/dev/io.openliberty.data.internal_fat_jpa/test-applications/DataJPATestApp/src/test/jakarta/data/jpa/web/DataJPATestServlet.java#L2048-L2053

Expected behavior
JPQL query should succeed and return the data.

Diagnostic information:

Additional context
Add any other context about the problem here.

Riva-Tholoor-Philip commented 4 months ago

See EclipseLink Issue : 2195

KyleAure commented 3 months ago

FYI @njr-11 @Riva-Tholoor-Philip

I was unable to recreate. I also un-commented and ran the original test and it works from Jakarta Data as well. Perhaps this bug was fixed in one of the beta versions of EclipseLink we have upgraded too?

My recreation attempt: https://github.com/KyleAure/open-liberty/commit/1483d53229d4e8898066114fb2ff1b9b014bc2bf

njr-11 commented 3 months ago

I was unable to recreate. I also un-commented and ran the original test and it works from Jakarta Data as well. Perhaps this bug was fixed in one of the beta versions of EclipseLink we have upgraded too?

Oh, I didn't realize it worked via Jakarta Data now, too. Then yes, EclipseLink must have fixed it already. I just tried it locally as well and given that worked, and I requested a build to confirm that its working there as well. I set up the PR to automatically close this issue.

njr-11 commented 3 months ago

When I attempted to re-enable this under #29200 I discovered that it's an intermittent issue that appears to happen when the test testEmbeddedId, which uses the same entity, runs first.

Riva-Tholoor-Philip commented 3 months ago

Thanks @njr-11

KyleAure commented 3 months ago

Reopening issue. The PR accidentally automatically closed this, it is still an issue that needs to be resolved.

covener commented 2 months ago

remove release:24.0.0.9 label (this OLGH is incorrectly in the fix pack metadata)