Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366112 - Tuple.get(int,java.lang.Class<X>) does not throw IllegalArgumentException - if element cannot be assigned to the specified type
Summary: Tuple.get(int,java.lang.Class<X>) does not throw IllegalArgumentException - i...
Status: CLOSED DUPLICATE of bug 366104
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-08 15:53 EST by Stephen DiMilla CLA
Modified: 2022-06-09 10:08 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen DiMilla CLA 2011-12-08 15:53:04 EST
Build Identifier: eclipselink-2.3.0.v20110604-r9504

Problem
Using Tuple.get(2, Date.class); should have thrown IllegalArgumentException when the element referenced can't be assigned to the specified type

----------------------

Using the entitys:

@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;
    }
}

----
@Entity
@Table(name = "ADDRESS")
public class Address implements java.io.Serializable {


    // Instance Variables
    private String id;
    private String street;
    private String city;
    private String state;
    private String zip;
    public Address() {
    }

    public Address(String id, String street, String city, String state, String zip) {
        this.id = id;
        this.street = street;
        this.city = city;
        this.state = state;
        this.zip = zip;
    }
    @Id
    @Column(name = "ID")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "STREET")
    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    @Column(name = "CITY")
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Column(name = "STATE")
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Column(name = "ZIP")
    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append(this.getClass().getSimpleName()+"[");
        result.append("id: " + getId());
        result.append(", street: " + getStreet());
        result.append(", city: " + getCity());
        result.append(", state: " + getState());
        result.append(", zip: " + getZip());
        result.append("]");
        return result.toString();
    }
}
----------------------
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"), customer.get("home"));
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 type");

try {
    t.get(2, Date.class);

    System.out.println("Did not get expected IllegalArgumentException for invalid type:" + t.get(2, Date.class));
} catch (IllegalArgumentException iae) {
    System.out.println("Got expected IllegalArgumentException");
} catch (Exception e) {
    System.out.println("Received unexpected exception", e);
}
----------------------


The output is:

Testing invalid type
Did not get expected IllegalArgumentException for invalid type:Address[id: 35, street: 8 Beverly Lane, city: HarwichPort, state: PA, zip: 45870]




Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:26 EDT
Updating target milestone.
Comment 2 Chris Delahunt CLA 2012-11-01 16:40:20 EDT

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