-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CurrencyConversionException using exchange rate providers #161
Comments
Agreed. I will check on my machine...
Am 05.07.2017 19:36 schrieb "Marcus Fihlon" <notifications@github.com>:
… 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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#161>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC5scyOmyKDg5Bo7Bv78VArPlPG1-QKyks5sK8mvgaJpZM4OOpXP>
.
|
I forgot to mention my versions:
<dependencies>
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build> |
Different code, same exception, different stack trace: final CurrencyConversion dollarConversion = MonetaryConversions.getConversion("USD");
final MonetaryAmount inEuro = Money.of(10, "EUR");
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("%s ≙ %s", inEuro, inDollar)); Very crazy: I run this program 10 times where 2 of them finished successful (output:
|
I cloned this repo and run the tests. As you can see, there are some failures related to conversion:
Complete build log: https://gist.github.com/McPringle/16bc55b579b76f3749c0e13a45cbffd7 Interesting side fact: There are some failures but the build was considered successful. Looks like the failsafe plugin fails the build only on errors, not on failures. Is this what you expect? |
definitivly not. there were a couple of changes. Seems I have to find time
now to restsbilize things...😕
Strange behaviour: I assume it relates to the initial loading of the rates
in the provider...
Am 06.07.2017 04:21 schrieb "Marcus Fihlon" <notifications@github.com>:
… I cloned this repo and run the tests. As you can see, there are some
failures related to conversion:
Results :
Failed tests:
DefaultNumberValueTest.shouldReturnAmountFractionDenominator:132 expected:<21> but was:<100>
DefaultNumberValueTest.shouldReturnAmountFractionNumerator:126 expected:<132> but was:<21>
IMFHistoricRateProviderTest.shouldConvertsBrazilianToDollar:143 » CurrencyConversion
IMFHistoricRateProviderTest.shouldConvertsDollarToBrazilian:156 » CurrencyConversion
IMFHistoricRateProviderTest.shouldConvertsDollarToEuro:117 » CurrencyConversion
IMFHistoricRateProviderTest.shouldConvertsEuroToDollar:130 » CurrencyConversion
IMFHistoricRateProviderTest.shouldSetTimeInLocalDateTime:226 » CurrencyConversion
IMFHistoricRateProviderTest.shouldSetTimeInLocalDateTime2:176 » CurrencyConversion
IMFRateProviderTest.shouldConvertsBrazilianToDollar:132 » CurrencyConversion C...
IMFRateProviderTest.shouldConvertsDollarToBrazilian:145 » CurrencyConversion C...
IMFRateProviderTest.shouldConvertsDollarToEuro:106 » CurrencyConversion Cannot...
IMFRateProviderTest.shouldConvertsEuroToDollar:119 » CurrencyConversion Cannot...
MonetaryConversionTest.testGetExchangeRateDefault:45 » CurrencyConversion Cann...
MonetaryConversionTest.testGetExchangeRateProvider_Chained:61 expected [true] but found [false]
MonetaryConversionTest.testMonetaryConversionsIMF:84 » CurrencyConversion Cann...
Tests run: 85, Failures: 15, Errors: 0, Skipped: 0
[ERROR] There are test failures.
Please refer to /Users/mcpringle/GitHub/other/jsr354-ri/moneta-convert/moneta-convert-imf/target/surefire-reports for the individual test results.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Moneta (JSR 354 RI) 1.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Moneta Parent ...................................... SUCCESS [ 0.124 s]
[INFO] Moneta Core ........................................ SUCCESS [ 19.036 s]
[INFO] Moneta Currency Conversion (Parent) ................ SUCCESS [ 0.001 s]
[INFO] Moneta Currency Conversion ......................... SUCCESS [ 2.216 s]
[INFO] Moneta Currency Conversion - ECB Provider .......... SUCCESS [ 37.363 s]
[INFO] Moneta Currency Conversion - IMF Provider .......... SUCCESS [ 9.014 s]
[INFO] Moneta (JSR 354 RI) ................................ SUCCESS [ 0.000 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:09 min
[INFO] Finished at: 2017-07-06T04:05:31+02:00
[INFO] Final Memory: 24M/308M
[INFO] ------------------------------------------------------------------------
Complete build log: https://gist.github.com/McPringle/
16bc55b579b76f3749c0e13a45cbffd7
Interesting side fact: There are some failures but the build was
considered successful. Looks like the failsafe plugin fails the build only
on errors, not on failures. Is this what you expect?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#161 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC5sc2OBY2nvQ9Ei6ICdXy8OefnWV6Drks5sLEScgaJpZM4OOpXP>
.
|
Any chance to test the same against https://github.com/JavaMoney/jsr354-ri-bp ? |
My test codefinal 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)); I'll run this code ten times with each of three different versions of the implementation. Test with Moneta backport v1.1<dependencies>
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api-bp</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta-bp</artifactId>
<version>1.1</version>
</dependency>
</dependencies> Mostly works (about 8 out of 10 runs):
Sometimes crashes (2 out of 10 runs):
Test with Moneta v1.1<dependencies>
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.1</version>
</dependency>
</dependencies> Crashes on every run:
Test with Moneta v1.0<dependencies>
<dependency>
<groupId>javax.money</groupId>
<artifactId>money-api</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.0</version>
</dependency>
</dependencies> Works on every run:
|
Thanks for the detailed analysis. Looks like Moneta 1.1 introduced an issue here. Must be solved before seriously considering the next release. |
On July 13th I'll be in Zürich. If you can't reproduce or need help, maybe there is some time to meet @atsticks? |
@McPringle @atsticks that would be great. Initially hoped 1.2 could be out by July 12, but at least this and possible other showstoppers must be fixed. It seems unrelated to modularization, because 1.1 was still a "monolith". Note, the Moneta 1.0 test with API 1.0.1 makes little sense, because you'd get API 1.0 as a transient dependency under the hood, but the API has not changed, so there's only a minor difference for Moneta-BP because the API was build against Java 7. |
OK, my assumption has been correct: the ECB provider (the others providers as well), does throw an error until the currencies have been successfully loaded:
Code used:
Best solution to be implemented IMO would be:
WDYT? |
My opinion: If you throw an exception if I try to use an exchange provider that is not completely initialized, as a user of Moneta I will have to check for this exception everywhere I need the excchange rates. My preferred usage of Moneta would be to do the loading asynchronously and if I try to access the exchange rates while the loading is still in progress, these calls will be blocked until the loading is finished or a timeout occurs (with a descriptive exception). I make a difference between these two exceptions and how to handle them. The first one (rate provider not completely initialized) will happen quite often. The second one (timeout) will only occur if there are errors somewhere (e.g. broken internet access, network problems, rate exchange data server down etc). If the first exceptions occurs I will try again a few times or for a certain amount of time, if the second exception occurs I will do nothing and accept that it does not work for now: my business code will look cleaner and contain less technical code. |
OK, so it's a concurrency or if you want "Transactional" issue here. Hope, a generic enough solution can be found, either directly in the RI or as a well-documented instruction for end users and applications. Any idea why the backports are not affected? |
Should not be an issue, it is fully an RI issue and there is
java.util.concurrent...
I wll try to have a look at it at the weekend or next week...
J Anatole
2017-07-07 12:52 GMT+02:00 Werner Keil <notifications@github.com>:
… OK, so it's a concurrency or if you want "Transactional" issue here. Hope,
a generic enough solution can be found, either directly in the RI or as a
well-documented instruction for end users and applications. Any idea why
the backports are not affected?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#161 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC5sc63aubaGVSzMDFVYZoZBEv-wFWEpks5sLg32gaJpZM4OOpXP>
.
--
*Anatole Tresch*
PPMC Member Apache Tamaya
JCP Star Spec Lead
*Switzerland, Europe Zurich, GMT+1*
*maketechsimple.wordpress.com <http://maketechsimple.wordpress.com/> *
*Twitter: @atsticks, @tamayaconf*
[image: GeeCON] [image: JSD_Speaker_2017]
|
Any news about this issue? On August 3rd we'll have a Hackergarten in Lucerne starting at 6pm, maybe you (@atsticks) are able to attend? It would be a nice project for the evening but I think we are not able to dive deep enough into the topic without any help. Or it could be a reason to organise a Hackergarten in Zürich, too… |
@McPringle @atsticks Yes, please do if you can. There are 4 showstoppers here (at least 1 also in the BP, but if e.g. a service call has race conditions etc. it is very likely also affected by this one) and until all of them are fixed no new fix pack is justified. |
I actually fixed the issue in the java 8 version, but did not yet push it
because of the imf provider issues. And I am currently in holidays until
end of July... so give me some time to put things together during weekend;)
J Anatole
Am 24.07.2017 14:43 schrieb "Marcus Fihlon" <notifications@github.com>:
Any news about this issue? On August 3rd we'll have a Hackergarten
<https://www.meetup.com/Hackergarten-Luzern/events/241448406/> in Lucerne
starting at 6pm, maybe you (@atsticks <https://github.com/atsticks>) are
able to attend? It would be a nice project for the evening but I think we
are not able to dive deep enough into the topic without any help. Or it
could be a reason to organise a Hackergarten
<https://www.meetup.com/Hackergarten-Zurich/> in Zürich, too…
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#161 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC5sc7ZjmvOVex6SHxnepAuph-MFmeHCks5sRJGIgaJpZM4OOpXP>
.
|
Checked in today the fixes for jsr354-ri (Java 8 version). Please test and provide feedback. |
Thanks, great work. How about a backport? |
Checkedin some minutes ago ;-)
2017-07-29 13:45 GMT+02:00 Werner Keil <notifications@github.com>:
… Thanks, great work. How about a backport?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#161 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC5sc2lNZn_m_FZUWzkSual8tsnIyuYsks5sSxtDgaJpZM4OOpXP>
.
--
*Anatole Tresch*
PPMC Member Apache Tamaya
JCP Star Spec Lead
*Switzerland, Europe Zurich, GMT+1*
*maketechsimple.wordpress.com <http://maketechsimple.wordpress.com/> *
*Twitter: @atsticks, @tamayaconf*
[image: GeeCON] [image: JSD_Speaker_2017]
|
I tried to convert a currency using the following piece of code:
The result was the following exception:
From my point of view this code should work.
The text was updated successfully, but these errors were encountered: