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

Bug 369632

Summary: [DB] Wrong conversion to Long and Integer
Product: [Modeling] EMF Reporter: Ales Dolecek <ales_d>
Component: cdo.net4j.dbAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3 CC: stepper
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

Description Ales Dolecek CLA 2012-01-25 04:06:28 EST
Build Identifier: 4.0.0.v20110607-1031

In org.eclipse.net4j.db.DBUtil methods

selectMinimumInt
selectMinimumLong
selectMaximumInt
selectMaxmiumLong

The Number is converted to appropriate type with cast:

Number number = ...
if (number instanceof Integer)
{
  return (Integer)number;
}
else if (number == null)
{
  return 0;
}

throw new DBException("Not an integer number: " + number); //$NON-NLS-1$

Better way however is:

Number number = ...
if (number == null) {
  return 0;
}
return Integer.valueOf(number.intValue())

---

Although this conversion can lose information if the number is actually "out of range" of Integer or Long it works with other numeric types returned from database - eg. BigDecimal in case of Oracle.

Reproducible: Sometimes

Steps to Reproduce:
Happends if the underlying database use different Number subclass to represent Integer and Long values.
Comment 1 Eike Stepper CLA 2012-08-14 22:51:52 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 2 Eike Stepper CLA 2012-09-21 04:00:16 EDT
commit 24f0afcd08bbf8c05baa750100db3de425a6af24
Comment 3 Eike Stepper CLA 2012-10-30 02:21:31 EDT
Port to 4.1 via bug 393112.
Comment 4 Eike Stepper CLA 2013-06-27 03:31:49 EDT
Available in R20130613-1157 (4.2)