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

Bug 366104

Summary: Tuple.get(int) does not throw IllegalArgumentException when int exceeds length of result tuple
Product: z_Archived Reporter: Stephen DiMilla <stephen.dimilla>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: blocker    
Priority: P3 CC: lance.andersen, stephen.dimilla, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
proposed fix and test cases
none
fix and tests cases none

Description Stephen DiMilla CLA 2011-12-08 15:27:26 EST
Build Identifier: eclipselink-2.3.0.v20110604-r9504

Problem
Using Tuple.get(99) should have thrown IllegalArgumentException when only 2 values exist in the Tuple
----------------------

Using the entity:

@Entity
@Table(name="CUSTOMER_TABLE")
public class Customer implements java.io.Serializable
{

    // Instance variables
    private String id;
    private String name;
    public Customer()
    {
    }

    public Customer (String id, String name)
    {
	this.id = id;
	this.name = name;
    }
   @Id
    @Column(name="ID")
    public String getId() {
	return id;
    }
    public void setId(String v) {
	this.id = v;
    }
 
    @Column(name="NAME")
    public String getName() {
	return name;
    }
    public void setName(String v) {
	this.name = v;
    }
}
----------------------
Using the client code:

CriteriaBuilder cbuilder = getEntityManager().getCriteriaBuilder();
et.begin();
CriteriaQuery<Tuple> cquery = cbuilder.createTupleQuery();
Root<Customer> customer = cquery.from(Customer.class);

System.out.println("Use Tuple Query");
cquery.multiselect(customer.get("id"), customer.get("name"));
TypedQuery<Tuple> tq = getEntityManager().createQuery(cquery);

List<Tuple> result = tq.getResultList();

Tuple t = result.get(0);
 System.out.println("Testing valid index");
 System.out.println("value:" + t.get(1, String.class));

System.out.println("Testing invalid index");
try {
        t.get(99, String.class);
        System.out.println("Did not get expected IllegalArgumentException for invalid index:" + t.get(99, String.class));
} catch (IllegalArgumentException iae) {
        System.out.println("Got expected IllegalArgumentException");
} catch (Exception e) {
        System.out.println("Received unexpected exception", e);
}
----------------------


The output is:

Testing valid index
value:Alan E. Frechette
Testing invalid index
Received unexpected exception
java.lang.IndexOutOfBoundsException: Index: 99, Size: 2
 	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
 	at java.util.ArrayList.get(ArrayList.java:322)
 	at org.eclipse.persistence.queries.ReportQueryResult.getByIndex(ReportQueryResult.java:474)
 	at org.eclipse.persistence.internal.jpa.querydef.TupleImpl.get(TupleImpl.java:82)
 	at org.eclipse.persistence.internal.jpa.querydef.TupleImpl.get(TupleImpl.java:69)



Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:18 EDT
Updating target milestone.
Comment 2 Chris Delahunt CLA 2012-10-31 16:33:26 EDT
Created attachment 223053 [details]
proposed fix and test cases

Proposed fix also includes minor fixes to resolve 366104 366112 366179 366182 as they all touch on the same issue.
Comment 3 Chris Delahunt CLA 2012-11-01 16:38:43 EDT
Created attachment 223094 [details]
fix and tests cases

latest patch has a minor change to the validation logic.  

This also fixes problems described in bugs 366112, 366179 and 366182
Validation tests added to JUnitCriteriaSimpleTestSuite

checked into main(2.5)
reviewed by Gordon Yorke
Comment 4 Chris Delahunt CLA 2012-11-01 16:39:30 EDT
*** Bug 366182 has been marked as a duplicate of this bug. ***
Comment 5 Chris Delahunt CLA 2012-11-01 16:40:10 EDT
fixed
Comment 6 Chris Delahunt CLA 2012-11-01 16:40:20 EDT
*** Bug 366112 has been marked as a duplicate of this bug. ***
Comment 7 Chris Delahunt CLA 2012-11-01 16:42:08 EDT
*** Bug 366179 has been marked as a duplicate of this bug. ***
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:16:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:23:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink