Skip to content
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

UnknownCurrencyException(CurrencyCode=EUR) #158

Closed
MystyxMac opened this issue May 10, 2017 · 24 comments
Closed

UnknownCurrencyException(CurrencyCode=EUR) #158

MystyxMac opened this issue May 10, 2017 · 24 comments
Assignees

Comments

@MystyxMac
Copy link

MystyxMac commented May 10, 2017

How can I resolve this issue? This happens with versions 1.0 and 1,1 on Java 8u111 and higher.

When I use

CurrencyUnit currency = Monetary.getCurrency(valuta);

I get an

UnknownCurrencyException(CurrencyCode=EUR)

Can this be a timing issue? Is the JDKCurrencyProvider lazy loaded?

@keilw keilw added the bug label May 12, 2017
@AlexanderYastrebov
Copy link
Contributor

@MystyxMac Can you reproduce it always or from time to time?

@MystyxMac
Copy link
Author

@AlexanderYastrebov When we had this bug, it was every time we ran our program. Now we added a workaround. That is we added Monetary.getCurrency("EUR"); to one of the classes that gets loaded first.
With this the error was gone. If i have time, I'll check if I can reproduce it.

@keilw keilw added the analysis label Jul 6, 2017
@keilw
Copy link
Member

keilw commented Jul 6, 2017

@MystyxMac Thanks a lot. If there's a workaround, it won't be considered a showstopper at this point (bugs or other issues that MUST be fixed before a new release is justified)

@AlexanderYastrebov
Copy link
Contributor

AlexanderYastrebov commented Jul 7, 2017

@keilw I had seen this issue on one of our instances yesterday (for different currency) and solved it temporarily by restarting the instance so it can reinitialize. The issue was constantly observed, so it is not a first-time/startup problem and I do not think it can be solved by additional early method call.
From my POV currently:

  1. It exists
  2. It is not reproducible
  3. There is no fix

@AlexanderYastrebov
Copy link
Contributor

I think it is important to mention that we faced the issue with

<dependency>
    <groupId>javax.money</groupId>
    <artifactId>money-api-bp</artifactId>
    <version>1.0</version>
</dependency>

@MystyxMac
Copy link
Author

We have this problem with

<dependency>
    <groupId>org.javamoney</groupId>
    <artifactId>moneta</artifactId>
    <version>1.1</version>
</dependency>

@keilw
Copy link
Member

keilw commented Jul 7, 2017

@AlexanderYastrebov did you mean Moneta-BP 1.0? You won't use money-api-bp with moneta, only via moneta-bp.

@whiskeysierra
Copy link

@keilw (I'm part of @AlexanderYastrebov's team). Not sure I understand your comment correctly. We're using Java 7 and therefore are required to use the backport. We're not using moneta (1.8+), just the backport.

@AlexanderYastrebov
Copy link
Contributor

I have a test case which will reproduce the problem. See https://github.com/AlexanderYastrebov/unknown-currency

@AlexanderYastrebov
Copy link
Contributor

@keilw @MystyxMac I got the point about workaround now, thanks. Static initialization like

    static {
        //
        // Initialize currency list early to avoid unsafe lazy multithreaded initialization
        //
        Monetary.getCurrency("EUR");
    }

should probably do the trick

@AlexanderYastrebov
Copy link
Contributor

My system properties where I can reproduce it with test case:

$ java -version && uname -a
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
Linux zamd 3.13.0-123-generic #172-Ubuntu SMP Mon Jun 26 18:04:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

@MystyxMac
Copy link
Author

@AlexanderYastrebov Thanks and nice that you could reproduce it. Yes, we use that workaround too. Is there something to fix or is this by design and is the workaround necessary?

@AlexanderYastrebov
Copy link
Contributor

With static block in place I can not reproduce it anymore with test case.
@MystyxMac Until the core issue is discovered and fixed we have to go with workaround.

@AlexanderYastrebov
Copy link
Contributor

Also possible to reproduce with

    <dependencies>
        <dependency>
            <groupId>org.javamoney</groupId>
            <artifactId>moneta-bp</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ unknown-currency ---
[INFO] com.github.ayastrebov:unknown-currency:jar:1.0.0-SNAPSHOT
[INFO] \- org.javamoney:moneta-bp:jar:1.1:compile
[INFO]    +- javax.money:money-api-bp:jar:1.0.1:compile
[INFO]    \- javax.annotation:javax.annotation-api:jar:1.2:compile

@AlexanderYastrebov
Copy link
Contributor

With moneta-bp:1.1 stacktrace is slightly different (note BaseMonetaryCurrenciesSingletonSpi vs DefaultMonetaryCurrenciesSingletonSpi):

java.util.concurrent.ExecutionException: UnknownCurrencyException [currencyCode=EUR]
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.github.ayastrebov.unknown.currency.Main.main(Main.java:21)
Caused by: UnknownCurrencyException [currencyCode=EUR]
	at org.javamoney.moneta.spi.base.BaseMonetaryCurrenciesSingletonSpi.getCurrency(BaseMonetaryCurrenciesSingletonSpi.java:53)
	at javax.money.Monetary.getCurrency(Monetary.java:150)
	at com.github.ayastrebov.unknown.currency.Main$Task.call(Main.java:35)
	at com.github.ayastrebov.unknown.currency.Main$Task.call(Main.java:31)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)

and also have got different kind of error once:

java.util.concurrent.ExecutionException: java.util.ServiceConfigurationError: javax.money.spi.CurrencyProviderSpi: Provider org.javamoney.moneta.internal.JDKCurrencyProvider could not be instantiated
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.github.ayastrebov.unknown.currency.Main.main(Main.java:21)
Caused by: java.util.ServiceConfigurationError: javax.money.spi.CurrencyProviderSpi: Provider org.javamoney.moneta.internal.JDKCurrencyProvider could not be instantiated
	at java.util.ServiceLoader.fail(ServiceLoader.java:232)
	at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at org.javamoney.moneta.internal.PriorityAwareServiceProvider.loadServices(PriorityAwareServiceProvider.java:117)
	at org.javamoney.moneta.internal.PriorityAwareServiceProvider.getServices(PriorityAwareServiceProvider.java:75)
	at javax.money.spi.Bootstrap.getServices(Bootstrap.java:109)
	at org.javamoney.moneta.internal.DefaultMonetaryCurrenciesSingletonSpi.getDefaultProviderChain(DefaultMonetaryCurrenciesSingletonSpi.java:112)
	at org.javamoney.moneta.internal.DefaultMonetaryCurrenciesSingletonSpi.collectProviders(DefaultMonetaryCurrenciesSingletonSpi.java:69)
	at org.javamoney.moneta.internal.DefaultMonetaryCurrenciesSingletonSpi.getCurrencies(DefaultMonetaryCurrenciesSingletonSpi.java:42)
	at org.javamoney.moneta.spi.base.BaseMonetaryCurrenciesSingletonSpi.getCurrency(BaseMonetaryCurrenciesSingletonSpi.java:50)
	at javax.money.Monetary.getCurrency(Monetary.java:150)
	at com.github.ayastrebov.unknown.currency.Main$Task.call(Main.java:35)
	at com.github.ayastrebov.unknown.currency.Main$Task.call(Main.java:31)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.util.HashMap$TreeNode
	at java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1827)
	at java.util.HashMap$TreeNode.treeify(HashMap.java:1944)
	at java.util.HashMap.treeifyBin(HashMap.java:771)
	at java.util.HashMap.putVal(HashMap.java:643)
	at java.util.HashMap.put(HashMap.java:611)
	at org.javamoney.moneta.internal.JDKCurrencyProvider.<init>(JDKCurrencyProvider.java:43)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
	... 16 more

@keilw
Copy link
Member

keilw commented Jul 7, 2017

@MystyxMac @AlexanderYastrebov That is why I was questioning the dependency

<dependency>
    <groupId>org.javamoney</groupId>
    <artifactId>moneta</artifactId>
    <version>1.1</version>
</dependency>

Which would not work with Java SE 7 and the API Backport.
The more recent information just above shows, it's moneta-bp.

Could you please continue the Moneta-BP relevant findings and conversation in JavaMoney/jsr354-ri-bp#37

Keeping this one open simply to try reproduce the issue in Moneta (you don't have to do that) or port any resolutions to the Java 8+ version, but please let's discuss the Java 7 issues in the ri-bp ticket now.

@AlexanderYastrebov
Copy link
Contributor

@keilw

That is why I was questioning the dependency

I can reproduce it with

    <dependencies>
        <dependency>
            <groupId>org.javamoney</groupId>
            <artifactId>moneta</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ unknown-currency ---
[INFO] com.github.ayastrebov:unknown-currency:jar:1.0.0-SNAPSHOT
[INFO] \- org.javamoney:moneta:jar:1.1:compile
[INFO]    +- javax.money:money-api:jar:1.0.1:compile
[INFO]    \- javax.annotation:javax.annotation-api:jar:1.2:compile
java.util.concurrent.ExecutionException: UnknownCurrencyException [currencyCode=EUR]
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at com.github.ayastrebov.unknown.currency.Main.main(Main.java:21)
Caused by: UnknownCurrencyException [currencyCode=EUR]
	at javax.money.spi.MonetaryCurrenciesSingletonSpi.getCurrency(MonetaryCurrenciesSingletonSpi.java:74)
	at javax.money.Monetary.getCurrency(Monetary.java:422)
	at com.github.ayastrebov.unknown.currency.Main$Task.call(Main.java:35)
	at com.github.ayastrebov.unknown.currency.Main$Task.call(Main.java:31)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)

let's discuss the Java 7 issues in the ri-bp ticket now.

Ok, though I am sure the core issue is the same

@AlexanderYastrebov
Copy link
Contributor

I have updated test case to support different moneta versions

@keilw
Copy link
Member

keilw commented Jul 7, 2017

Thanks, so it happens both with Moneta and Moneta-BP?

ConcurrentException sounds like it could be related to #161 which @atsticks already analyzed. Please have a look, if they are related, it makes it easier to find a solution to both or consider them "duplicates".

@whiskeysierra
Copy link

whiskeysierra commented Jul 7, 2017 via email

@keilw
Copy link
Member

keilw commented Jul 7, 2017

Multiple modules in the sense that Moneta is now broken into sub-modules, or do you mean Moneta vs. Moneta-BP?

@whiskeysierra
Copy link

I was referring to different parts of the library, maybe feature would have been a better word. In particular it looks like there similar bugs in the initialization of currencies (this issue) and exchange rates (#161).

@keilw
Copy link
Member

keilw commented Jul 8, 2017

Happy if someone was willing to help on that. It does require JCP membership, unless Zalando joined by now, everyone who wants to help (and if they like also be listed) as contributor could join as Associate members.

@atsticks
Copy link
Member

atsticks commented Jul 11, 2017

Effectively I am currently fixing some issues with lazy initialization on the conversion side as well. I will check the currency loading as well... To be clear: IMO we should fix this:

  • loading the JDKProvider asap, the latest with first access.
  • Ensure all providers handle lazy initialization/initial loading correcty as let clients wait until a first load is done

AFAIK the code in backport and Java 8 is quite similar, so I assume the same issues on both version to be present.

@atsticks atsticks self-assigned this Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants