Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullpointerexception when using coalesce or selectcase function under stress #1867

Open
LateshDulani opened this issue Apr 19, 2023 · 3 comments

Comments

@LateshDulani
Copy link

After upgrading to eclipselink 2.7.11, we have seen a issue where criteria query which is using either coalesce or selectcase function is throwing Nullpointerexception under stress.
We also see that bug is not db dependent or platform dependent. We are able to reproduce with oracle and postgres db while running on weblogic or with helidon mp.
exception is ::
at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1598)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:694)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:968)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:624)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:881)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1191)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:485)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1279)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:3004)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1898)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1880)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1845)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:262)
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:482)
... 35 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.expressions.ExpressionOperator.printCollection(ExpressionOperator.java:2391)
at org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression.printSQL(ArgumentListFunctionExpression.java:102)
at org.eclipse.persistence.expressions.ExpressionOperator.printCollection(ExpressionOperator.java:2400)
at org.eclipse.persistence.internal.expressions.FunctionExpression.printSQL(FunctionExpression.java:581)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.appendOrderClauseToWriter(SQLSelectStatement.java:787)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.printSQLOrderByClause(SQLSelectStatement.java:1831)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.printSQL(SQLSelectStatement.java:1758)
at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement(DatabasePlatform.java:3586)
at org.eclipse.persistence.platform.database.PostgreSQLPlatform.printSQLSelectStatement(PostgreSQLPlatform.java:543)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:868)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:879)
at org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:885)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:393)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.prepareSelectAllRows(StatementQueryMechanism.java:318)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1724)
at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:910)
at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:841)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:675)
... 47 more

Exception only occur under load so i am sure that issue is related to thread safety of argumentIndices variable in ExpressionOperator class.

I am attaching a sample which is build with helidon and I have three flavor of sql which all fail with same error. Sample can be run with both oracle or postgres by changing commented lines in
pom.xml
persistence.xml
application.yaml

This issue is very critical to us because without using coalesce or selectcase we can not achieve nulllast sorting using criteria. So, please suggest any workaround if possible.

thanks

sample_bug_nullpointer.tar.gz

@CarlosMOGoncalves
Copy link

Hello there,

I would just like to second this one.
In a remarkable coincidence, this has also happened recently to my team's project.
I am aware that a correction has been issued for this matter here but somehow an edge case might have slipped through.

In our project's scenario it happened after we replaced an SQL query with a JPQL equivalent which had an ORDER BY with multiple CASE WHEN statements. This using JPA EntityManagers with Stateless EJBs.

In order to trigger it, one needs to use multiple concurrent threads, all triggering such query and eventually this will pop up.
I might be able to provide some more information, if needed.

@Sollder11
Copy link

Hello,

I would like to add that this persists in 3.0.4.
For all searching for a workaround, calling CriteriaBuilder->function with coalesce works just fine.
If someone can guide me in the right direction, I can take a look and try to fix it.

Greetings, Benedict

@igormukhin
Copy link
Contributor

fixed in 2.7.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants