Project

General

Profile

Bug #4994

NPE in AdaptiveQuery when loading null data for an outer join

Added by Eric Faulhaber over 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:

History

#1 Updated by Eric Faulhaber over 3 years ago

When a CompoundQuery has a component using the OUTER JOIN option, we try to load data via the AdaptiveQuery.load(Object[], LockType, boolean) API. It is possible for the Object[] data parameter to contain null elements if no joining record was found for a row.

Recreate: choose the "T Rates" menu option in the Hotel ChUI sample application. Using 3821c/11787, this results in:

Caused by: java.lang.NullPointerException
        at com.goldencode.p2j.persist.AdaptiveQuery.load(AdaptiveQuery.java:2465)
        at com.goldencode.p2j.persist.CompoundQuery.loadByValues(CompoundQuery.java:2268)
        at com.goldencode.p2j.persist.CompoundQuery.next(CompoundQuery.java:1097)
        at com.goldencode.p2j.persist.CompoundQuery.next(CompoundQuery.java:997)
        at com.goldencode.p2j.persist.QueryWrapper.next(QueryWrapper.java:2094)
        at com.goldencode.p2j.ui.BrowseWidget.getRows(BrowseWidget.java:4503)
        at com.goldencode.p2j.ui.BrowseWidget.getRows(BrowseWidget.java:4319)
        at com.goldencode.p2j.ui.LogicalTerminal.getRows(LogicalTerminal.java:13481)
        ...

The problematic line is:

arr[i] = ((Record) data[i]).primaryKey();

If we prevent the NPE, however, we still have to make the subsequent call to

repositionByID(arr, true, false)

safe.

The last parameter to the AdaptiveQuery.load method is boolean silentIfNullId. It seems to have been introduced for this very purpose, and is used in several other places in this method, but somehow this case was missed.

#2 Updated by Ovidiu Maxiniuc about 3 years ago

  • Status changed from New to WIP

In case of OUTER JOIN tables when there is no matching record, data[i] is null. Rewriting the problematic line as:

arr[i] = (data[i] == null) ? null : ((Record) data[i]).primaryKey();

seems to be correctly handled downstream, no record being loaded into the respective buffer.

Committed revision 3821c/12070.

#4 Updated by Eric Faulhaber about 2 years ago

  • Assignee set to Ovidiu Maxiniuc

Ovidiu Maxiniuc wrote:

[...]
Committed revision 3821c/12070.

Can this be closed?

#5 Updated by Ovidiu Maxiniuc about 2 years ago

  • % Done changed from 0 to 100

Yes, I think so. I do not think I heard of any related issues or regressions because of this.

#6 Updated by Eric Faulhaber about 2 years ago

  • Status changed from WIP to Closed

Thanks.

Also available in: Atom PDF