[JAVA-2040] Type casting int and long while using get fails but doesn't throw any exception and gets stuck. Created: 18/Nov/15  Updated: 25/Nov/15  Resolved: 25/Nov/15

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Anshul Goel Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Comments   
Comment by Jeffrey Yemin [ 25/Nov/15 ]

Hi Anshul,

As you haven't responded to my question in a while, I'm closing this ticket, but feel free to comment at a later time and I can re-open.

Comment by Jeffrey Yemin [ 18/Nov/15 ]

I'm not sure what you mean. Consider this small test:

        BasicDBObject obj = new BasicDBObject("x", 4L);   // set to a long value, which will get boxed to a Long
        int x = (int) obj.get("x");

It will throw a ClassCastException, as expected, since a Long can not be un-boxed to an int:

Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

Comment by Anshul Goel [ 18/Nov/15 ]

The problem is :

Suppose I have an DBObject object;

int x = (int) object.get(key); would get stuck if value returned by object.get(key) is long or vice versa.

Generated at Thu Feb 08 08:56:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.