< prev index next >
src/java.base/share/classes/java/text/CompactNumberFormat.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -404,10 +404,15 @@
*/
@Override
public final StringBuffer format(Object number,
StringBuffer toAppendTo,
FieldPosition fieldPosition) {
+
+ if (number == null) {
+ throw new IllegalArgumentException("Cannot format null as a number");
+ }
+
if (number instanceof Long || number instanceof Integer
|| number instanceof Short || number instanceof Byte
|| number instanceof AtomicInteger
|| number instanceof AtomicLong
|| (number instanceof BigInteger
@@ -1051,10 +1056,15 @@
* @param index index in the array of compact patterns
*
*/
private void applyPattern(String pattern, int index) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("A null compact pattern" +
+ " encountered at index: " + index);
+ }
+
int start = 0;
boolean gotNegative = false;
String positivePrefix = "";
String positiveSuffix = "";
< prev index next >