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

NumberFormat.getInstance(locale).parse() does not work correctly even after -H:+IncludeAllLocales in native mode #36876

Closed
vincejv opened this issue Nov 5, 2023 · 4 comments · Fixed by #37106
Assignees
Labels
Milestone

Comments

@vincejv
Copy link

vincejv commented Nov 5, 2023

Describe the bug

Sample code fragment, wherein beanT.locale = Locale.FRANCE

@Inject
BeanT beanT;

@GET
public void hello(HttpServerResponse serverResponse) throws ParseException {
    serverResponse.putHeader("Content-Type", "text/plain;charset=utf-8");
    LOGGER.info("Locale hello() {}", beanT.getLocale());
    double v = NumberFormat.getInstance(beanT.getLocale()).parse("0,27").doubleValue();
    LOGGER.info("double v: {}", v);
    serverResponse.send(String.valueOf(v));
}

Logs in JVM Mode

2023-11-05 11:02:27,645 INFO  [org.acm.BeanTProducer] (executor-thread-1) Locale fr-FR
2023-11-05 11:02:27,647 INFO  [org.acm.GreetingResource] (executor-thread-1) Locale hello() fr_FR
2023-11-05 11:02:27,649 INFO  [org.acm.GreetingResource] (executor-thread-1) double v: 0.27

Logs in Native Mode

2023-11-05 11:00:16,066 INFO  [org.acm.BeanTProducer] (executor-thread-1) Locale fr-FR
2023-11-05 11:00:16,066 INFO  [org.acm.GreetingResource] (executor-thread-1) Locale hello() fr_FR
2023-11-05 11:00:16,068 INFO  [org.acm.GreetingResource] (executor-thread-1) double v: 27.0

GraalVM is picking up the options as per compilation logs

------------------------------------------------------------------------------------------------------------------------
 5 experimental option(s) unlocked:
 - '-H:+IncludeAllLocales' (origin(s): command line)
 - '-H:+AllowFoldMethods' (origin(s): command line)
 - '-H:BuildOutputJSONFile' (origin(s): command line)
 - '-H:-UseServiceLoaderFeature' (origin(s): command line)
 - '-H:ReflectionConfigurationResources' (origin(s): 'META-INF/native-image/io.micrometer/micrometer-core/native-image.properties' in 'file:///project/lib/io.micrometer.micrometer-core-1.11.1.jar', 'META-INF/native-image/io.netty/netty-transport/native-image.properties' in 'file:///project/lib/io.netty.netty-transport-4.1.100.Final.jar')
------------------------------------------------------------------------------------------------------------------------

Expected behavior

Native and JVM mode should have the same outputs when using NumberFormat.getInstance(locale).parse(), given the same locale and input

Actual behavior

Native and JVM modes have varying outputs given the same locale and input when using NumberFormat.getInstance(locale).parse()

How to Reproduce?

Reproducer: https://github.com/vincejv/qbt-expt-test

Steps to reproduce:

  1. Compile and run in native mode
  2. Set qbittorrent.exporter.locale as fr-FR or any other locale besides en-US
  3. Call localhost:17871/metrics/hello endpoint
  4. Varying outputs between JVM and native modes

Output of uname -a or ver

Both Github actions and Linux vince-MS-7681 6.2.0-36-generic #37~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct 9 15:34:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

21.0.1+12-LTS, vendor version: Mandrel-23.1.1.0-Final

Mandrel or GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.5.0

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 8.3

Additional information

Blocking my proposed PR in migrating an OSS prometheus exporter to Quarkus
caseyscarborough/qbittorrent-exporter#20

@vincejv vincejv added area/native-image kind/bug Something isn't working labels Nov 5, 2023
Copy link

quarkus-bot bot commented Nov 5, 2023

/cc @Karm (mandrel), @galderz (mandrel), @zakkak (mandrel)

@vincejv vincejv changed the title NumberFormat.getInstance(locale)..parse() does not work correctly even after -H:+IncludeAllLocales in native mode NumberFormat.getInstance(locale).parse() does not work correctly even after -H:+IncludeAllLocales in native mode Nov 5, 2023
@vincejv
Copy link
Author

vincejv commented Nov 6, 2023

I have managed to workaround the issue by setting quarkus.locales for specific locales needed, but I need to define all the possible locales available in JVM as the application has an arbitrary configurable locale by the user, adding a new locale every time JVM has a new locale is quite tedious, I was expecting -H:+IncludeAllLocales to include all locales already

@Karm Karm self-assigned this Nov 6, 2023
@Karm
Copy link
Member

Karm commented Nov 10, 2023

I have the reproducer working. WIP...

@Karm
Copy link
Member

Karm commented Nov 14, 2023

I have a patch and a test, but I still need to fix side effects, e.g.
quarkus.locales=all
and
quarkus.locales=en,hr-HR,en-US,fr-FR
should both work for Hibernate validator, but the former makes it drop to default, English even for a language lookup tag that prefers Croatian language. That is the aftermath of me internally interpreting all as Locale.ROOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants