0

I try to make a program using Locale. I want compile natively this program with GraalVM but Locale don't have the same behavior after native compiling.

I success to isolate the problem with the following program :

import java.text.NumberFormat;
import java.util.Locale;
import java.util.Currency;

public class HelloWorld {

  public static void main(String[] args) {
    NumberFormat gbNumberFormat = NumberFormat.getCurrencyInstance(new Locale("en", "GB"));
    gbNumberFormat.setCurrency(Currency.getInstance("USD"));
    System.out.println(gbNumberFormat.format(1337));

    NumberFormat usNumberFormat = NumberFormat.getCurrencyInstance(new Locale("en", "US"));
    usNumberFormat.setCurrency(Currency.getInstance("USD"));
    System.out.println(usNumberFormat.format(1337));
  }

}

I can compile this program in Java :

javac -d out/ HelloWorld.java

And execute it (from out directory) :

java HelloWorld

The result is :

US$1,337.00
$1,337.00

I can now make the native image and launch it :

native-image -cp out/ HelloWorld
./helloworld

The result is not the same :

$1,337.00
$1,337.00

It is look likes I have a problem with i18n in native mode. I don't really understand why. I am using graalvm-ce-java11-20.0.0 but I tested with previous versions with same behavior.

I am at your disposal if necessary.

Stéphane
  • 63
  • 6
  • That is odd, but are you sure it's really a bug? They use £ for their own money, and they might have some €. But both of those are not $. – Elliott Frisch May 04 '20 at 04:43
  • Locale is for localisation, it decide the format : by example for fr_FR, currecy is wrote after number and not before beacause it is their habit. Locale and Currency and completly seperate concept. I don't know if it is a bug or not. May I just have to specify option to embedd all locales. I don't have solution but I just want the same behavior in 'normal' or 'native' mode. – Stéphane May 04 '20 at 05:45
  • Similar to this problem : https://stackoverflow.com/questions/61567216/graalvm-quarkus-locale-in-native-mode – Stéphane May 05 '20 at 21:17

0 Answers0