@@ -349,10 +349,11 @@ public String getInfinity() {
349
349
* unchanged.
350
350
*
351
351
* @param infinity the string representing infinity
352
+ * @throws NullPointerException if {@code infinity} is {@code null}
352
353
*/
353
354
public void setInfinity (String infinity ) {
355
+ this .infinity = Objects .requireNonNull (infinity );
354
356
hashCode = 0 ;
355
- this .infinity = infinity ;
356
357
}
357
358
358
359
/**
@@ -370,10 +371,11 @@ public String getNaN() {
370
371
* unchanged.
371
372
*
372
373
* @param NaN the string representing "not a number"
374
+ * @throws NullPointerException if {@code NaN} is {@code null}
373
375
*/
374
376
public void setNaN (String NaN ) {
377
+ this .NaN = Objects .requireNonNull (NaN );
375
378
hashCode = 0 ;
376
- this .NaN = NaN ;
377
379
}
378
380
379
381
/**
@@ -414,14 +416,18 @@ public String getCurrencySymbol()
414
416
}
415
417
416
418
/**
417
- * Sets the currency symbol for the currency of these
418
- * DecimalFormatSymbols in their locale.
419
+ * Sets the currency symbol for the currency of this
420
+ * {@code DecimalFormatSymbols} in their locale. Unlike {@link
421
+ * #setInternationalCurrencySymbol(String)}, this method does not update
422
+ * the currency attribute nor the international currency symbol attribute.
419
423
*
420
424
* @param currency the currency symbol
425
+ * @throws NullPointerException if {@code currency} is {@code null}
421
426
* @since 1.2
422
427
*/
423
428
public void setCurrencySymbol (String currency )
424
429
{
430
+ Objects .requireNonNull (currency );
425
431
initializeCurrency (locale );
426
432
hashCode = 0 ;
427
433
currencySymbol = currency ;
@@ -448,35 +454,29 @@ public String getInternationalCurrencySymbol()
448
454
* this also sets the currency attribute to the corresponding Currency
449
455
* instance and the currency symbol attribute to the currency's symbol
450
456
* in the DecimalFormatSymbols' locale. If the currency code is not valid,
451
- * then the currency attribute is set to null and the currency symbol
452
- * attribute is not modified.
457
+ * then the currency attribute and the currency symbol attribute are not modified.
453
458
*
454
459
* @param currencyCode the currency code
460
+ * @throws NullPointerException if {@code currencyCode} is {@code null}
455
461
* @see #setCurrency
456
462
* @see #setCurrencySymbol
457
463
* @since 1.2
458
464
*/
459
- public void setInternationalCurrencySymbol (String currencyCode )
460
- {
465
+ public void setInternationalCurrencySymbol (String currencyCode ) {
466
+ Objects .requireNonNull (currencyCode );
467
+ // init over setting currencyInit flag as true so that currency has
468
+ // fallback if code is not valid
461
469
initializeCurrency (locale );
462
470
hashCode = 0 ;
463
471
intlCurrencySymbol = currencyCode ;
464
- currency = null ;
465
- if (currencyCode != null ) {
466
- try {
467
- currency = Currency .getInstance (currencyCode );
468
- currencySymbol = currency .getSymbol ();
469
- } catch (IllegalArgumentException e ) {
470
- }
471
- }
472
+ try {
473
+ currency = Currency .getInstance (currencyCode );
474
+ currencySymbol = currency .getSymbol (locale );
475
+ } catch (IllegalArgumentException _) {} // Simply ignore if not valid
472
476
}
473
477
474
478
/**
475
- * Gets the currency of these DecimalFormatSymbols. May be null if the
476
- * currency symbol attribute was previously set to a value that's not
477
- * a valid ISO 4217 currency code.
478
- *
479
- * @return the currency used, or null
479
+ * {@return the {@code Currency} of this {@code DecimalFormatSymbols}}
480
480
* @since 1.4
481
481
*/
482
482
public Currency getCurrency () {
@@ -485,7 +485,7 @@ public Currency getCurrency() {
485
485
}
486
486
487
487
/**
488
- * Sets the currency of these DecimalFormatSymbols.
488
+ * Sets the currency of this {@code DecimalFormatSymbols} .
489
489
* This also sets the currency symbol attribute to the currency's symbol
490
490
* in the DecimalFormatSymbols' locale, and the international currency
491
491
* symbol attribute to the currency's ISO 4217 currency code.
@@ -497,9 +497,7 @@ public Currency getCurrency() {
497
497
* @see #setInternationalCurrencySymbol
498
498
*/
499
499
public void setCurrency (Currency currency ) {
500
- if (currency == null ) {
501
- throw new NullPointerException ();
502
- }
500
+ Objects .requireNonNull (currency );
503
501
initializeCurrency (locale );
504
502
hashCode = 0 ;
505
503
this .currency = currency ;
@@ -555,9 +553,7 @@ public String getExponentSeparator()
555
553
*/
556
554
public void setExponentSeparator (String exp )
557
555
{
558
- if (exp == null ) {
559
- throw new NullPointerException ();
560
- }
556
+ Objects .requireNonNull (exp );
561
557
hashCode = 0 ;
562
558
exponentialSeparator = exp ;
563
559
}
@@ -767,7 +763,8 @@ public boolean equals(Object obj) {
767
763
patternSeparator == other .patternSeparator &&
768
764
infinity .equals (other .infinity ) &&
769
765
NaN .equals (other .NaN ) &&
770
- getCurrencySymbol ().equals (other .getCurrencySymbol ()) && // possible currency init occurs here
766
+ // Currency fields are lazy. Init via get call to ensure non-null
767
+ getCurrencySymbol ().equals (other .getCurrencySymbol ()) &&
771
768
intlCurrencySymbol .equals (other .intlCurrencySymbol ) &&
772
769
currency == other .currency &&
773
770
monetarySeparator == other .monetarySeparator &&
@@ -800,7 +797,8 @@ public int hashCode() {
800
797
patternSeparator ,
801
798
infinity ,
802
799
NaN ,
803
- getCurrencySymbol (), // possible currency init occurs here
800
+ // Currency fields are lazy. Init via get call to ensure non-null
801
+ getCurrencySymbol (),
804
802
intlCurrencySymbol ,
805
803
currency ,
806
804
monetarySeparator ,
0 commit comments