Skip to content

Add defensive null check to stop null pointer exception - #1702

Open
Mustard wants to merge 6 commits into
eclipse-ee4j:masterfrom
Mustard:master
Open

Mustard wants to merge 6 commits into
eclipse-ee4j:masterfrom
Mustard:master

Conversation

@Mustard

@Mustard Mustard commented Sep 12, 2022

Copy link
Copy Markdown

When joining tables (entities) that have a @customizer (history policy) eclipselink will throw a NullPointerException

I have a simple proof of concept project that demonstrates the issue. Ideally this could be added to the eclipselink project as a test, any help around where to add this test in the project would be appreciated as I couldn't even get the 2.7 branch to build locally and am unfamiliar with the project

This pull request would resolve this issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=526836

A possible other solution / improvement might be to initialise asOfClause in org.eclipse.persistence.internal.expressions.DataExpression such that it is not null in the first place

protected AsOfClause asOfClause = AsOfClause.NO_CLAUSE;

I have agreed to the Eclipse Contributor Agreement https://www.eclipse.org/user/mustard

@lukasj

lukasj commented Sep 13, 2022

Copy link
Copy Markdown
Member

wrt test - take a look at jpa/eclipselink.jpa.testapps and try to find an existing test this could be added to - jpa.test.advanced or jpa.test.jpql look like good candidates; it does not make much sense to add whole new project for this

@Mustard

Mustard commented Nov 22, 2022

Copy link
Copy Markdown
Author

Hi @lukasj

Thanks for your help!

Took me a while to get back to it but I have added tests to the pull request, if there is anything else I can do to move this along let me know

@lukasj

lukasj commented Mar 1, 2026

Copy link
Copy Markdown
Member

at the time of submission, ECA was valid

@robertpatrick

Copy link
Copy Markdown
Contributor

@arjantijms I reproduced the original problem and a new regression using current 5.x code with the PR’s production changes:

Test Current master Full PR change Two null guards only
Prepare the reported join NPE Pass Pass
Historical joined query Past parent + past child Past parent + current child Past parent + past child

The problem is the new AsOfClause.NO_CLAUSE initializer. Previously, null allowed a child expression to inherit its parent’s historical timestamp. NO_CLAUSE prevents that inheritance, silently mixing historical and current data.

What the author should do:

  1. Remove that initializer, retaining the two targeted null guards—the narrower variant passed both local tests.
  2. Add a historical-join result test and close the test’s EntityManager. The existing preparation test is meaningful and correctly registered.
  3. Refresh onto master and obtain clean CI, including the existing tests affected by adding history policies to Room/Door.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants