Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351509

Summary: Null Pointer Exception when using Scrollable Cursor on a OneToMany Mapping
Product: z_Archived Reporter: Rohit Banga <rohit.banga>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: david.minsky, iamrohitbanga, mohamad.raja, rohit.banga, tom.ware
Version: unspecifiedKeywords: core
Target Milestone: ---   
Hardware: All   
OS: Windows XP   
Whiteboard: paging, scrollable cursor, pagination
Attachments:
Description Flags
Sample Code to reproduce the issue
none
Proposed patch and testcase
none
Patch and testcase
none
Patch and testcase
none
Patch and testcase none

Description Rohit Banga CLA 2011-07-08 01:50:36 EDT
Build Identifier: Eclipselink-2.3

A NullPointerException when trying to execute a ReadAllQuery with scrollable cursor enabled. It seems that the exception happens when it tries to access the many side of the mapping.
I am using Eclipselink-2.3. Here is the stack trace:

Exception in thread "main" java.lang.NullPointerException
    at org.eclipse.persistence.internal.queries.JoinedAttributeManager.processDataResults(JoinedAttributeManager.java:1074)
    at org.eclipse.persistence.queries.ScrollableCursor.retrieveNextObject(ScrollableCursor.java:557)
    at org.eclipse.persistence.queries.ScrollableCursor.loadNext(ScrollableCursor.java:397)
    at org.eclipse.persistence.queries.ScrollableCursor.hasNext(ScrollableCursor.java:263)
    at ScrollableCursorTest.main(ScrollableCursorTest.java:80)


Link to the discussion on the list:
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg06356.html

Reproducible: Always

Steps to Reproduce:
1. Try accessing the many side of the relationship for an entity returned by a scrollable cursor.
2. Uploaded Sample code to reproduce the issue. Testing with a simple Employee,Phone example.
3.
Comment 1 Rohit Banga CLA 2011-07-08 01:57:08 EDT
Created attachment 199306 [details]
Sample Code to reproduce the issue

Please run the code on a database containing the following two tables:

1. empinfo4
   id - string
   name - string

2. phone4
   phone - int
   empid - string (foreign key)
Comment 2 Tom Ware CLA 2011-07-21 08:46:16 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 David Minsky CLA 2011-07-21 10:19:33 EDT
Reproduced issue with a testcase based on our Employee demo:

   ReadAllQuery query = new ReadAllQuery(Employee.class);
   ExpressionBuilder builder = query.getExpressionBuilder();

   query.addJoinedAttribute(builder.anyOfAllowingNone("phoneNumbers"));
   query.useScrollableCursor(5);

   ScrollableCursor cursor = (ScrollableCursor) getSession().executeQuery(query);

   while (cursor.hasNext()) {
      System.out.println(cursor.next());
   }

This produces:

[EL Info]: ServerSession(13884241)--ThreeTierEmployee login successful
[EL Fine]: ServerSession(13884241)--Connection(23664622)--SELECT DISTINCT t1.EMP_ID, t2.EMP_ID, t1.F_NAME, t1.GENDER, t1.L_NAME, t2.SALARY, t1.END_TIME, t1.START_TIME, t1.END_DATE, t1.START_DATE, t1.ADDR_ID, t1.MANAGER_ID, t1.VERSION, t0.TYPE, t0.AREA_CODE, t0.P_NUMBER, t0.EMP_ID FROM EMPLOYEE t1 LEFT OUTER JOIN PHONE t0 ON (t0.EMP_ID = t1.EMP_ID), SALARY t2 WHERE (t2.EMP_ID = t1.EMP_ID)
Employee: Betty Jones
Employee: John Way
Employee: Sarah-Lou Smitty
Employee: Fred Jones
Employee: Jill May
Employee: Charles Chanley
Employee: Sarah-Lou Smitty
Employee: Sarah Way
Employee: Emanual Smith
Employee: Marcus Saunders
Employee: Bob Smith
Employee: Jim-Bob Jefferson
Employee: Charles Chanley
java.lang.NullPointerException
[EL Config]: ServerSession(13884241)--Connection(23664622)--disconnect
	at org.eclipse.persistence.internal.queries.JoinedAttributeManager.processDataResults(JoinedAttributeManager.java:1074)
	at org.eclipse.persistence.queries.ScrollableCursor.retrieveNextObject(ScrollableCursor.java:557)
	at org.eclipse.persistence.queries.ScrollableCursor.loadNext(ScrollableCursor.java:397)
	at org.eclipse.persistence.queries.ScrollableCursor.hasNext(ScrollableCursor.java:263)
	at examples.sessions.threetier.examples.ScrollableCursorTest.run(ScrollableCursorTest.java:25)
	at examples.sessions.threetier.Example.runExample(Example.java:57)
	at examples.sessions.threetier.examples.ScrollableCursorTest.main(ScrollableCursorTest.java:31)
Comment 4 David Minsky CLA 2011-07-21 10:20:44 EDT
Potentially related to: Bug 309142 - ScrollableCursor hasNext() throws DB exception instead of returning false at end of iteration
Comment 5 David Minsky CLA 2011-07-26 17:16:11 EDT
Created attachment 200400 [details]
Proposed patch and testcase
Comment 6 David Minsky CLA 2011-10-24 14:26:17 EDT
Created attachment 205852 [details]
Patch and testcase

Patch fixes ScrollableCursor retrieveNextObject(), and moves positioning code block before the joining check to fix the occurrence of a NPE.
Comment 7 David Minsky CLA 2011-10-24 14:37:07 EDT
Created attachment 205859 [details]
Patch and testcase

Minor modification to testing
Comment 8 David Minsky CLA 2011-10-24 15:31:02 EDT
Created attachment 205864 [details]
Patch and testcase

Adjusted copyright header on test, and removed unused import
Comment 9 David Minsky CLA 2011-10-24 18:18:19 EDT
Checked into trunk (2.4) at revision: 10266
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:36:24 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink