freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: Proper template error message when DecimalFormat.format throws ArithmeticException.
Date Wed, 16 Sep 2015 17:33:19 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 25f3b824b -> 89ec237f4


Proper template error message when DecimalFormat.format throws ArithmeticException.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/89ec237f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/89ec237f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/89ec237f

Branch: refs/heads/2.3-gae
Commit: 89ec237f42a28ba0f0b31a100b09e3c7c586fda0
Parents: 25f3b82
Author: ddekany <ddekany@apache.org>
Authored: Wed Sep 16 19:32:25 2015 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Wed Sep 16 19:32:25 2015 +0200

----------------------------------------------------------------------
 .../java/freemarker/core/JavaTemplateNumberFormat.java   |  7 ++++++-
 .../java/freemarker/core/ExtendedDecimalFormatTest.java  | 11 ++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/89ec237f/src/main/java/freemarker/core/JavaTemplateNumberFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/JavaTemplateNumberFormat.java b/src/main/java/freemarker/core/JavaTemplateNumberFormat.java
index 3c1763c..b34414b 100644
--- a/src/main/java/freemarker/core/JavaTemplateNumberFormat.java
+++ b/src/main/java/freemarker/core/JavaTemplateNumberFormat.java
@@ -52,7 +52,12 @@ final class JavaTemplateNumberFormat extends BackwardCompatibleTemplateNumberFor
 
     @Override
     String format(Number number) throws UnformattableNumberException {
-        return javaNumberFormat.format(number);
+        try {
+            return javaNumberFormat.format(number);
+        } catch (ArithmeticException e) {
+            throw new UnformattableNumberException(
+                    "This format can't format the " + number + " number. Reason: " + e.getMessage(),
e);
+        }
     }
 
     public NumberFormat getJavaNumberFormat() {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/89ec237f/src/test/java/freemarker/core/ExtendedDecimalFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/ExtendedDecimalFormatTest.java b/src/test/java/freemarker/core/ExtendedDecimalFormatTest.java
index 0c5c9f2..d53fc84 100644
--- a/src/test/java/freemarker/core/ExtendedDecimalFormatTest.java
+++ b/src/test/java/freemarker/core/ExtendedDecimalFormatTest.java
@@ -278,9 +278,14 @@ public class ExtendedDecimalFormatTest extends TemplateTest {
                 + "<#setting locale='de_DE'>${1000.15}; "
                 + "<#setting numberFormat='0.0;;rnd=d'>${1000.15}",
                 "1_000.2; 10 00.2; 1_000,2; 1000,1");
-        assertErrorContains("${1?string('#E')}", "\"#E\"", "format string", "exponential");
-        assertErrorContains("<#setting numberFormat='#E'>${1}", "\"#E\"", "format string",
"exponential");
-        assertErrorContains("<#setting numberFormat=';;foo=bar'>${1}", "\"foo\"", "supported");
+        assertErrorContains("${1?string('#E')}",
+                TemplateException.class, "\"#E\"", "format string", "exponential");
+        assertErrorContains("<#setting numberFormat='#E'>${1}",
+                TemplateException.class, "\"#E\"", "format string", "exponential");
+        assertErrorContains("<#setting numberFormat=';;foo=bar'>${1}",
+                TemplateException.class, "\"foo\"", "supported");
+        assertErrorContains("<#setting numberFormat='0;;rnd=un'>${1.5}",
+                TemplateException.class, "can't format", "1.5", "UNNECESSARY");
     }
 
     private void assertFormatted(String formatString, Object... numberAndExpectedOutput)
throws ParseException {


Mime
View raw message