JavaMoney / jsr354-ri-bp

Backport of the JSR 354 RI compatible with Java prior to SE8.
Other
9 stars 14 forks source link

CurrencyConversionException using exchange rate providers #41

Closed atsticks closed 7 years ago

atsticks commented 7 years ago

See #JavaMoney/jsr354-ri/161 :

I tried to convert a currency using the following piece of code:

final MonetaryAmount inEuro = Money.of(10, "EUR");
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("%s: %s ≙ %s", rateProvider, inEuro, inDollar));

The result was the following exception:

Exception in thread "main" CurrencyConversionException [base=EUR, term=null, conversionContext=null]: Cannot convert EUR into null
    at org.javamoney.moneta.spi.AbstractCurrencyConversion.apply(AbstractCurrencyConversion.java:109)
    at org.javamoney.moneta.Money.with(Money.java:377)
    at org.javamoney.moneta.Money.with(Money.java:58)
    at CurrencyConversionDemo.main(CurrencyConversionDemo.java:34)

From my point of view this code should work.