miachm/SODS

OfficeCurrency#equals throws NullPointerException when currency is null

adn35350 opened this issue ยท 1 comments

It's me again ๐Ÿ˜ƒ

After the pull-request #48 the default currency was set to null instead of non-null currency (e.g : locale default currency). That's your choice but this creates a regression on OfficeCurrency#equals method because variable that.currency can be null.

Here is a simple JUnit test for this use case

@Test
void testOfficeCurrencyEqualsWithNullCurrency() {
  final OfficeCurrency nonNullCurrency = new OfficeCurrency(Currency.getInstance(Locale.getDefault()), 5D);
  final OfficeCurrency nullCurrency = new OfficeCurrency(null, 5D);
  Assertions.assertFalse(nonNullCurrency.equals(nullCurrency));
}

Result :

java.lang.NullPointerException
	at com.github.miachm.sods.OfficeCurrency.equals(OfficeCurrency.java:61)

Thanks for the report!

I think it's an edge case in the equals method. Easy fix.