FasterXML / jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Apache License 2.0
2.25k stars 773 forks source link

Locale deserialization fails on locales with only a language and variant #1273

Closed lyleschemmerling closed 4 months ago

lyleschemmerling commented 4 months ago

Seen on 2.15.3, tested on 2.17.0 using openjdk 21.0.2 2024-01-16 LTS OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)

This simple test fails:

@Test
public void test() throws Exception {
  var objectMapper = new ObjectMapper();
  var locale = new Locale.Builder().setLanguage("be").setVariant("TARASK").build();

  assertEquals(locale, objectMapper.readValue(objectMapper.writeValueAsString(locale), Locale.class));
}

It's a strange Locale that I am not sure is valid but it is listed when invoking Locale.getAvailableLocales(). I have some code that iterates over all of them and ensures that we are handling them correctly via some API calls and in moving to Java 21 from 17 the tests started to fail. Ideally, the serialization to deserialization would never fail regardless of the input.

Let me know if you have more questions.

pjfanning commented 4 months ago

Can you provide the stacktrace? It is a real courtesy - not expecting other people to run the code to see the issue.

lyleschemmerling commented 4 months ago

closing. I realized my mistake, the issue is with locale.toLanguageTag()