JavaMoney / jsr354-ri

JSR 354 - Moneta: Reference Implementation
Other
334 stars 100 forks source link

java.lang.IllegalStateException: AmbiguousConfiguration detected for 'org.javamoney.moneta.Money.defaults.roundingMode' #393

Open debraj-manna opened 1 year ago

debraj-manna commented 1 year ago

I am using moneta 1.4.2 with spring-boot 3.0.6 and Java 17.

I am seeing an exception trace like below. Can someone let me know what could be causing this and how can I get around this?

Jun 01, 2023 7:39:38 PM org.javamoney.moneta.spi.MonetaryConfig <init>
SEVERE: Error loading javamoney.properties, ignoring jar:file:/Users/debrajmanna/.m2/repository/com/spotnana/lambda/profile-uploads/0.0.1-SNAPSHOT/profile-uploads-0.0.1-SNAPSHOT.jar!/javamoney.properties
java.lang.IllegalStateException: AmbiguousConfiguration detected for 'org.javamoney.moneta.Money.defaults.roundingMode'.
        at org.javamoney.moneta.spi.MonetaryConfig.updateConfig(MonetaryConfig.java:86)
        at org.javamoney.moneta.spi.MonetaryConfig.<init>(MonetaryConfig.java:49)
        at org.javamoney.moneta.spi.MonetaryConfig.<clinit>(MonetaryConfig.java:35)
        at org.javamoney.moneta.spi.DefaultMonetaryCurrenciesSingletonSpi.getDefaultProviderChain(DefaultMonetaryCurrenciesSingletonSpi.java:121)
        at org.javamoney.moneta.spi.DefaultMonetaryCurrenciesSingletonSpi.collectProviders(DefaultMonetaryCurrenciesSingletonSpi.java:91)
        at org.javamoney.moneta.spi.DefaultMonetaryCurrenciesSingletonSpi.getCurrencies(DefaultMonetaryCurrenciesSingletonSpi.java:45)
        at javax.money.spi.MonetaryCurrenciesSingletonSpi.getCurrency(MonetaryCurrenciesSingletonSpi.java:76)
        at javax.money.Monetary.getCurrency(Monetary.java:382)
        at org.javamoney.moneta.FastMoney.<clinit>(FastMoney.java:118)
        at com.spotnana.common.MoneyUtils.protoMoney(MoneyUtils.java:104)
keilw commented 1 year ago

Moved that one to the RI. It is a known issue during test execution, related to #370, mostly because the maven test module does not declare a Jigsaw module-info of its own. To try reproduce it fro a standalone setup, @debraj-manna could you please provide a snippet from the MoneyUtils class if you can?

debraj-manna commented 1 year ago

@keilw

  public static com.spotnana.proto.v1.common.Money protoMoney(double amount, String currency) {
    return protoMoney(FastMoney.of(BigDecimal.roundToScale5(amount), currency));
  }
keilw commented 7 months ago

@debraj-manna Does it still happen with 1.4.4? And if so, is the problem restricted to JUnit tests?

kewne commented 4 months ago

@keilw I just noticed that there is a javamoney.properties~ (notice the tilde) in https://github.com/JavaMoney/jsr354-ri/tree/3415a66a09326f8e8bf07c21213b4d7eb4cf561a/moneta-core/src/main/resources, which is incredibly suspicious.

keilw commented 4 months ago

@kewne That's a template or backup, it should not be loaded, and the ambiguity comes from problems with MonetaryConfig: #370