summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-20 16:01:05 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-05-20 16:01:06 +0000
commita1ece7ecd8d1803dc568807ed677079716d6556d (patch)
tree4b0f06b36302363a2842320d0f210c61f5befef1
parentf315df1cb0768bec10ada80d30d7069d15ac76ba (diff)
parent7f0856090f176550fb3b8834afa46eb5813ee329 (diff)
downloadlibcore-a1ece7ecd8d1803dc568807ed677079716d6556d.zip
libcore-a1ece7ecd8d1803dc568807ed677079716d6556d.tar.gz
libcore-a1ece7ecd8d1803dc568807ed677079716d6556d.tar.bz2
Merge "Add regression tests for null arguments to DecimalFormat."
-rw-r--r--luni/src/test/java/libcore/java/text/DecimalFormatTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/java/text/DecimalFormatTest.java b/luni/src/test/java/libcore/java/text/DecimalFormatTest.java
index 1e40f8a..c58f83a 100644
--- a/luni/src/test/java/libcore/java/text/DecimalFormatTest.java
+++ b/luni/src/test/java/libcore/java/text/DecimalFormatTest.java
@@ -21,7 +21,9 @@ import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
+import java.text.FieldPosition;
import java.text.NumberFormat;
+import java.text.ParsePosition;
import java.util.Currency;
import java.util.Locale;
@@ -197,4 +199,65 @@ public class DecimalFormatTest extends junit.framework.TestCase {
df.setCurrency(Currency.getInstance("CHF"));
df.setCurrency(Currency.getInstance("GBP"));
}
+
+ // Check we don't crash on null inputs.
+ public void testBug15081434() throws Exception {
+ DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
+ try {
+ df.parse(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ try {
+ df.applyLocalizedPattern(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ try {
+ df.applyPattern(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ try {
+ df.applyPattern(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ try {
+ df.format(null, new StringBuffer(), new FieldPosition(0));
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ df.parse(null, new ParsePosition(0));
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ // This just ignores null.
+ df.setDecimalFormatSymbols(null);
+
+ try {
+ df.setCurrency(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+
+ // These just ignore null.
+ df.setNegativePrefix(null);
+ df.setNegativeSuffix(null);
+ df.setPositivePrefix(null);
+ df.setPositiveSuffix(null);
+
+ try {
+ df.setRoundingMode(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
}