tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 43656] New: - ELSupport.coerceToType modifies BigDecimal Values
Date Fri, 19 Oct 2007 01:02:47 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43656>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43656

           Summary: ELSupport.coerceToType modifies BigDecimal Values
           Product: Tomcat 6
           Version: 6.0.14
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Servlet & JSP API
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: mail@nils-eckert.de


If ELSupport.coerceToType is called with an BigDecimal instance as the first Parameter 'obj'
and 
BigDecimal.class as type it should return the inputted value.

Instead the BigDecimal is converted into a double and back into a BigDecimal which leads to
a diffenent 
value. This happens in Line 228:

        if (BigInteger.class.equals(type)) {
            if (number instanceof BigDecimal) {
                return ((BigDecimal) number).toBigInteger();
            }
            return BigInteger.valueOf(number.longValue()); // This leads to a different value.
        }

Example: Run the Method with new BigDecimal("0.19"), BigDecimal.class as parameters.
This should result in a BigDecimal with value 0.19. Instead i got 
0.190000000000000002220446049250313080847263336181640625.

 The easiest solution is to compare the class of the object to coerce with the target class
and return the 
inputted value if the are equal in ELSupport.coerceToType Method:

public final static Object coerceToType(final Object obj, final Class type) throws 
IllegalArgumentException {
		if (type == null || Object.class.equals(type) || type.equals(obj.getClass())) {
			return obj;
		}
...

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message