Skip to content

OAK-12051: Fix NPE when ordering union query by jcr:score#2746

Open
ChlineSaurus wants to merge 3 commits intoapache:OAK-12051from
ChlineSaurus:trunk
Open

OAK-12051: Fix NPE when ordering union query by jcr:score#2746
ChlineSaurus wants to merge 3 commits intoapache:OAK-12051from
ChlineSaurus:trunk

Conversation

@ChlineSaurus
Copy link
Contributor

Fixes the NullPointerException during UnionQuery sorting by the JCR score. The problem occurs if there is a score column, but accessing a score of that column returns Null. This can happen if, for example, there is a union between three queries, of which at least one has scores, and at least one doesn't have, and those two results are merged first.

Issue: https://issues.apache.org/jira/browse/OAK-12051

New behavior: If null values occur in such a column, we replace it with a zero. The warning from the illegalArgumentException was removed, as returning 0 occurs frequently and is nothing to worry about.

Original PR: #2687
Moved to merging from trunk to new branch to run evaluation

PropertyValue[] values = new PropertyValue[] {
PropertyValues.newString(path),
PropertyValues.newDouble(score)
score == null ? null : PropertyValues.newDouble(score)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me. What about:

Suggested change
score == null ? null : PropertyValues.newDouble(score)
PropertyValues.newDouble(score == null ? 0.0 : score)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for mocking behavior in tests. The goal is that it returns null, so the change would defeat the purpose in my opinion. The mock should be able to return null to test if the actual code can handle a null return.

What this (somewhat weird) line does is to ensure, that we only try to turn the value to be returned by the mock into a Double if it isn't null, with the goal that the same mocking code can be used for tests with null and actual scores.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see, you are right! Sorry I got confused.

}
return scoreValue.getValue(Type.DOUBLE);
} catch (IllegalArgumentException e) {
LOG.warn("Failed to get jcr:score for path={}", row.getPath(), e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey, I can change it. Two questions:

  • Should I reduce it to an Info/Debug log (in my understanding this could happen quite often)
  • Is path always given, or can it also be null (I don't want to introduce a new NPE when fixing one 😅)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it fails quite often, then we should probably change the code so that it first checks if the column is available, in order to not throw an exception in the first place.

if (scoreValue == null) {
return 0.0;
}
return scoreValue.getValue(Type.DOUBLE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also check the type... maybe there are nodes with a "jcr:score" property but it's text? Probably not, but I guess we should be conservative.

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

Successfully merging this pull request may close these issues.

2 participants