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 81518200D06 for ; Mon, 25 Sep 2017 17:16:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7F94F1609E9; Mon, 25 Sep 2017 15:16:18 +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 9AEA11609C4 for ; Mon, 25 Sep 2017 17:16:17 +0200 (CEST) Received: (qmail 46422 invoked by uid 500); 25 Sep 2017 15:16:16 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 46413 invoked by uid 99); 25 Sep 2017 15:16:16 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Sep 2017 15:16:16 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4FF77183F6A for ; Mon, 25 Sep 2017 15:16:16 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id IKPJcGxJh8pf for ; Mon, 25 Sep 2017 15:16:12 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id A43885FDB8 for ; Mon, 25 Sep 2017 15:16:11 +0000 (UTC) Received: (qmail 46261 invoked by uid 99); 25 Sep 2017 15:16:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Sep 2017 15:16:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id ECEF2F5652; Mon, 25 Sep 2017 15:16:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Mon, 25 Sep 2017 15:16:12 -0000 Message-Id: In-Reply-To: <224c532602614bd9adad7d84c96e954a@git.apache.org> References: <224c532602614bd9adad7d84c96e954a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/4] incubator-freemarker git commit: Bug fixed (part of FREEMARKER-48): When an arithmetic exception has occurred in an expression (typically division by zero), the template processing has thrown the ArithmeticException as is, without packaging it into archived-at: Mon, 25 Sep 2017 15:16:18 -0000 Bug fixed (part of FREEMARKER-48): When an arithmetic exception has occurred in an expression (typically division by zero), the template processing has thrown the ArithmeticException as is, without packaging it into a TemplateException. Thus, the error location in the template wasn't visible in the exception. Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/b246de24 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/b246de24 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/b246de24 Branch: refs/heads/2.3 Commit: b246de2403bac5b82c44a83cc3b7ab5b6617d0e8 Parents: ee1e922 Author: ddekany Authored: Mon Sep 18 22:49:56 2017 +0200 Committer: ddekany Committed: Mon Sep 18 22:49:56 2017 +0200 ---------------------------------------------------------------------- .../freemarker/core/ArithmeticExpression.java | 38 +++++++++++--------- src/manual/en_US/book.xml | 11 ++++++ .../freemarker/core/MiscErrorMessagesTest.java | 11 ++++++ .../core/StringLiteralInterpolationTest.java | 2 +- 4 files changed, 45 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b246de24/src/main/java/freemarker/core/ArithmeticExpression.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/ArithmeticExpression.java b/src/main/java/freemarker/core/ArithmeticExpression.java index 4fbe778..2ed7890 100644 --- a/src/main/java/freemarker/core/ArithmeticExpression.java +++ b/src/main/java/freemarker/core/ArithmeticExpression.java @@ -54,22 +54,28 @@ final class ArithmeticExpression extends Expression { static TemplateModel _eval(Environment env, TemplateObject parent, Number lhoNumber, int operator, Number rhoNumber) throws TemplateException, _MiscTemplateException { ArithmeticEngine ae = EvalUtil.getArithmeticEngine(env, parent); - switch (operator) { - case TYPE_SUBSTRACTION : - return new SimpleNumber(ae.subtract(lhoNumber, rhoNumber)); - case TYPE_MULTIPLICATION : - return new SimpleNumber(ae.multiply(lhoNumber, rhoNumber)); - case TYPE_DIVISION : - return new SimpleNumber(ae.divide(lhoNumber, rhoNumber)); - case TYPE_MODULO : - return new SimpleNumber(ae.modulus(lhoNumber, rhoNumber)); - default: - if (parent instanceof Expression) { - throw new _MiscTemplateException((Expression) parent, - "Unknown operation: ", Integer.valueOf(operator)); - } else { - throw new _MiscTemplateException("Unknown operation: ", Integer.valueOf(operator)); - } + try { + switch (operator) { + case TYPE_SUBSTRACTION : + return new SimpleNumber(ae.subtract(lhoNumber, rhoNumber)); + case TYPE_MULTIPLICATION : + return new SimpleNumber(ae.multiply(lhoNumber, rhoNumber)); + case TYPE_DIVISION : + return new SimpleNumber(ae.divide(lhoNumber, rhoNumber)); + case TYPE_MODULO : + return new SimpleNumber(ae.modulus(lhoNumber, rhoNumber)); + default: + if (parent instanceof Expression) { + throw new _MiscTemplateException((Expression) parent, + "Unknown operation: ", Integer.valueOf(operator)); + } else { + throw new _MiscTemplateException("Unknown operation: ", Integer.valueOf(operator)); + } + } + } catch (ArithmeticException e) { + throw new _MiscTemplateException(e, env, + "Arithmetic operation failed", + (e.getMessage() != null ? new String[] { ": ", e.getMessage() } : " (see cause exception)")); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b246de24/src/manual/en_US/book.xml ---------------------------------------------------------------------- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 210f674..edb158b 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -27179,6 +27179,17 @@ TemplateModel x = env.getVariable("x"); // get variable x + Bug fixed (part of FREEMARKER-48): + When an arithmetic exception has occurred in an expression + (typically division by zero), the template processing has thrown + the ArithmeticException as is, without + packaging it into a TemplateException. Thus, + the error location in the template wasn't visible in the + exception. + + + When logging error due to an error in an attempt directive block, the log message now indicates that the http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b246de24/src/test/java/freemarker/core/MiscErrorMessagesTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/freemarker/core/MiscErrorMessagesTest.java b/src/test/java/freemarker/core/MiscErrorMessagesTest.java index 79ccb2c..5799c12 100644 --- a/src/test/java/freemarker/core/MiscErrorMessagesTest.java +++ b/src/test/java/freemarker/core/MiscErrorMessagesTest.java @@ -19,9 +19,13 @@ package freemarker.core; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + import org.junit.Test; import freemarker.cache.TemplateNameFormat; +import freemarker.template.TemplateException; import freemarker.test.TemplateTest; public class MiscErrorMessagesTest extends TemplateTest { @@ -45,4 +49,11 @@ public class MiscErrorMessagesTest extends TemplateTest { assertErrorContains("${{}[10]}", "[]", "?api"); } + @Test + public void aritheticException() { + Throwable e = assertErrorContains("<#assign x = 0>\n${1 / x}", "Arithmetic"); + assertThat(e, instanceOf(TemplateException.class)); + assertEquals((Integer) 2, ((TemplateException) e).getLineNumber()); + } + } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b246de24/src/test/java/freemarker/core/StringLiteralInterpolationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/freemarker/core/StringLiteralInterpolationTest.java b/src/test/java/freemarker/core/StringLiteralInterpolationTest.java index b0d0581..f655865 100644 --- a/src/test/java/freemarker/core/StringLiteralInterpolationTest.java +++ b/src/test/java/freemarker/core/StringLiteralInterpolationTest.java @@ -80,7 +80,7 @@ public class StringLiteralInterpolationTest extends TemplateTest { public void testErrors() { addToDataModel("x", 1); assertErrorContains("${'${noSuchVar}'}", InvalidReferenceException.class, "missing", "noSuchVar"); - assertErrorContains("${'${x/0}'}", ArithmeticException.class, "zero"); + assertErrorContains("${'${x/0}'}", "zero"); } @Test