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

Bug 366179

Summary: Tuple.get(String) does not throw IllegalArgumentException if alias does not correspond to an element in the query result tuple
Product: z_Archived Reporter: Stephen DiMilla <stephen.dimilla>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED DUPLICATE QA Contact:
Severity: blocker    
Priority: P3 CC: christopher.delahunt, lance.andersen, stephen.dimilla, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Stephen DiMilla CLA 2011-12-09 08:05:18 EST
Build Identifier: eclipselink-2.3.0.v20110604-r9504

Problem
Using Tuple.get("doesnotexist") should have thrown IllegalArgumentException 
----------------------

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("NAME"));
System.out.println("Testing name does not exist");

try {
    t.get("doesnotexist", String.class);
    System.out.println("Did not get expected IllegalArgumentException for TupleElement, actual:" + t.get("doesnotexist", String.class));
} catch (IllegalArgumentException iae) {
    System.out.println("Got expected IllegalArgumentException");
}
----------------------


The output is:

Testing valid index
TRACE: value:Alan E. Frechette
Testing name does not exist
Did not get expected IllegalArgumentException for TupleElement, actual:null


Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:21 EDT
Updating target milestone.
Comment 2 Chris Delahunt CLA 2012-11-01 16:42:08 EDT

*** This bug has been marked as a duplicate of bug 366104 ***
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:33:13 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink