Bug 47428 - JSTL converts BigDecimal to Long
JSTL converts BigDecimal to Long
 Status: CLOSED INVALID None Taglibs Unclassified Standard Taglib (show other bugs) unspecified PC Windows Server 2003 P2 normal (vote) --- Tomcat Developers Mailing List

 Reported: 2009-06-25 09:05 UTC by void 2009-08-20 00:47 UTC (History) 1 user (show) hhfdna

Attachments

 Note You need to log in before you can comment on or make changes to this bug.
 void 2009-06-25 09:05:59 UTC ``` do something If foo is a BigDecimal,JSTL converts its type to Long,which means if foo is in the range [0,1), for example,0.01,it always return true! That is not correct. I checked SUN's JSP2.0 specification,in the JSP.2.3.5.7 section. It says: A {==,!=,eq,ne} B • If A==B, apply operator • If A is null or B is null return false for == or eq, true for != or ne. • If A or B is BigDecimal, coerce both A and B to BigDecimal and then: If operator is == or eq, return A.equals( B ) If operator is != or ne, return !A.equals( B ) • If A or B is Float or Double coerce both A and B to Double, apply operator • If A or B is BigInteger, coerce both A and B to BigInteger and then: If operator is == or eq, return A.equals( B ) If operator is != or ne, return !A.equals( B ) • If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to Long, apply operator • If A or B is Boolean coerce both A and B to Boolean, apply operator • If A or B is String coerce both A and B to String, compare lexically • Otherwise if an error occurs while calling A.equals(B), error • Otherwise, apply operator to result of A.equals(B) According to the third rule,it seems like no problem. but when I checked apache's implementation of JSTL, in the class org.apache.taglibs.standard.lang.jstl.Coercions,I found apache didn't implement the third specification.so the preceding example will be processed according to this rule: If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to Long, apply operator that is, it will convert BigDecimal to Long! so, is this a bug or something? looking forward to your answering.Thanks!``` Kris Schneider 2009-06-25 11:01:06 UTC `Maybe I missed something, but I didn't see *any* Big(Decimal|Integer) coercions in org.apache.taglibs.standard.lang.jstl.Coercions. Strange. So, I'd say it's a bug - the spec clearly states that BigDecimal coercion should take place before Long coercion.` void 2009-06-26 00:57:16 UTC ```ok,gotcha. Will apache fix it in the next version? The bug exists in the latest version:jakarta-taglibs-standard-1.1.2.zip By the way,do you know if there are other JSTL implementations besides apache's thanks!``` Kris Schneider 2009-06-29 07:59:19 UTC ```Well, I *did* miss something. I forgot that the EL implementation is now part of the container (as of JSP 2.0, I believe), and not part of JSTL. So, I guess I'm inclined to reject the bug. Any chance you can test your code on different containers to see if your results change? The Standard taglib code you reviewed should have been targeted at implementing the JSTL 1.0 spec (JSP 1.2), which doesn't use Big(Decimal|Integer) in its coercions for relational operators.``` void 2009-06-29 08:42:36 UTC ```(In reply to comment #3) > Well, I *did* miss something. I forgot that the EL implementation is now part > of the container (as of JSP 2.0, I believe), and not part of JSTL. So, I guess > I'm inclined to reject the bug. Any chance you can test your code on different > containers to see if your results change? > The Standard taglib code you reviewed should have been targeted at implementing > the JSTL 1.0 spec (JSP 1.2), which doesn't use Big(Decimal|Integer) in its > coercions for relational operators. We tried in Tomcat 5.0.28, and WebSphere 5. Both performed uncorrectly. Since it is as you said,what we gonna do for now? Is there a finnal solution for this situation? Thanks!``` Kris Schneider 2009-06-29 10:40:11 UTC ```Maybe you can provide some more detail on exactly what you're doing. Here's a test page, coerce.jsp (webapps/ROOT): <%@ page contentType="text/plain" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% pageContext.setAttribute("decimal", new java.math.BigDecimal("0.01")); %> decimal: \${decimal} decimal == 0: \${decimal == 0} true TC 5.0.28 decimal: 0.01 decimal == 0: false Notice that "true" does *not* get output. Hang on, is this exactly what you have in your page: Because it should be this: This discussion should also be moved to taglibs-user<>jakarta.apache.org``` Mark Thomas 2009-08-17 01:55:50 UTC `Update assignee to Tomcat dev list` Henri Yandell 2009-08-20 00:47:09 UTC `Closing as lack of response.`