Comments (24)
@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
from jsr354-ri.
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".
from jsr354-ri.
@MystyxMac Can you reproduce it always or from time to time?
from jsr354-ri.
@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.
from jsr354-ri.
@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)
from jsr354-ri.
@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:
- It exists
- It is not reproducible
- There is no fix
from jsr354-ri.
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>
from jsr354-ri.
We have this problem with
<dependency>
<groupId>org.javamoney</groupId>
<artifactId>moneta</artifactId>
<version>1.1</version>
</dependency>
from jsr354-ri.
@AlexanderYastrebov did you mean Moneta-BP 1.0? You won't use money-api-bp
with moneta
, only via moneta-bp
.
from jsr354-ri.
@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.
from jsr354-ri.
I have a test case which will reproduce the problem. See https://github.com/AlexanderYastrebov/unknown-currency
from jsr354-ri.
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
from jsr354-ri.
@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?
from jsr354-ri.
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.
from jsr354-ri.
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
from jsr354-ri.
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
from jsr354-ri.
@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.
from jsr354-ri.
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
from jsr354-ri.
I have updated test case to support different moneta versions
from jsr354-ri.
from jsr354-ri.
Multiple modules in the sense that Moneta is now broken into sub-modules, or do you mean Moneta vs. Moneta-BP?
from jsr354-ri.
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).
from jsr354-ri.
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.
from jsr354-ri.
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.
from jsr354-ri.
Related Issues (20)
- Document maven coordinates of JARs in Moneta User Guide HOT 2
- MonetaryConversions.getConversion loosing rate date for exchange rate providers HOT 7
- Money.of with scaled BigDecimal leads to unexpected getNumber value HOT 1
- Decomission Java 9 in CI pipeline
- Add Java 17 to CI pipeline
- moneta-core depends on JEE8, making it unusable with JEE9 HOT 9
- Published license identifier is not compliant with the SPDX license list
- Update TestNG to 7.7.1 or above
- Would you mind wrapping up a 1.4.3 release? HOT 23
- Unexpected rounding behaviour using FastMoney HOT 1
- Provider incorrectly marked as available + doesn't fallback to next provider in the chain HOT 7
- Money (USD) calculations not rounding properly HOT 1
- 1.4.3 Release Train HOT 1
- Fix Resource Caching based on ECB findings HOT 1
- Unnecessary logging on INFO level HOT 2
- java.lang.IllegalStateException: AmbiguousConfiguration detected for 'org.javamoney.moneta.Money.defaults.roundingMode' HOT 5
- DuplicateRelativeFileException when importing library in Android Studio HOT 4
- Convert org.javamoney.moneta.spi.loader.LoadableResource into an interface HOT 4
- Fix Logback issue
- Reactivate IMF in Moneta BOM
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsr354-ri.