Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C79F3200B12 for ; Sun, 12 Jun 2016 14:17:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C6211160A2C; Sun, 12 Jun 2016 12:17:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1A35F160A06 for ; Sun, 12 Jun 2016 14:17:21 +0200 (CEST) Received: (qmail 29830 invoked by uid 500); 12 Jun 2016 12:17:21 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 29819 invoked by uid 99); 12 Jun 2016 12:17:21 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jun 2016 12:17:21 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id EBF2A2C1F5C for ; Sun, 12 Jun 2016 12:17:20 +0000 (UTC) Date: Sun, 12 Jun 2016 12:17:20 +0000 (UTC) From: "Dagu Ward (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (JEXL-199) An Update to the Add Method MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 12 Jun 2016 12:17:23 -0000 [ https://issues.apache.org/jira/browse/JEXL-199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15326411#comment-15326411 ] Dagu Ward commented on JEXL-199: -------------------------------- Hi Thanks for the reponse, I will pass this information onto the spring jade developers and hopefully they will put in a fix on their end. If it was my code, it would already be fixed, but trying not to get into the libraries customization as that puts you in a tight spot with upgrades and updates. Thanks very much for your explanation. Hopefully they will comply nicely and help me to resolve the problem Thanks again > An Update to the Add Method > --------------------------- > > Key: JEXL-199 > URL: https://issues.apache.org/jira/browse/JEXL-199 > Project: Commons JEXL > Issue Type: Improvement > Affects Versions: 2.1.1, 3.0 > Reporter: Dagu Ward > Assignee: Henri Biestro > Priority: Critical > Fix For: 3.0.1 > > > If A String and a Boolean is passed to this method, it throws an expection and just dies. > Booleans (True or False) should be treated just like strings and just concatenated together, so that this would not cause any problems. > Spring jade currently uses this method when it is building html, and if a boolean is used in the string, it causes the parsing to die. > Not sure it is fully the intended purpose, so not reported as a bug, but as a nice improvement, but it sure causing me some stress. > You can easily put the return in the finally, check for boolean or just use the string function to return the string value > /** > * Add two values together. > *

> * If any numeric add fails on coercion to the appropriate type, > * treat as Strings and do concatenation. > *

> * > * @param left left argument > * @param right right argument > * @return left + right. > */ > public Object add(Object left, Object right) { > if (left == null && right == null) { > return controlNullNullOperands(); > } > /*** > Possible Fix > if (left instanceof Boolean){ > left = (Boolean.valueOf((boolean) left).toString()); > } > if (right instanceof Boolean){ > left = (Boolean.valueOf((boolean) right).toString()); > } > ***/ > boolean strconcat = strict > ? left instanceof String || right instanceof String > : left instanceof String && right instanceof String; > if (!strconcat) { > try { > // if either are bigdecimal use that type > if (left instanceof BigDecimal || right instanceof BigDecimal) { > BigDecimal l = toBigDecimal(left); > BigDecimal r = toBigDecimal(right); > BigDecimal result = l.add(r, getMathContext()); > return narrowBigDecimal(left, right, result); > } > // if either are floating point (double or float) use double > if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) { > double l = toDouble(left); > double r = toDouble(right); > return l + r; > } > // otherwise treat as integers > BigInteger l = toBigInteger(left); > BigInteger r = toBigInteger(right); > BigInteger result = l.add(r); > return narrowBigInteger(left, right, result); > } catch (java.lang.NumberFormatException nfe) { > if (left == null || right == null) { > controlNullOperand(); > } > } > } > return toString(left).concat(toString(right)); > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)