Skip to content

GH-5340: Use Locale.ROOT in toUpperCase calls for locale-neutral type normalization#6048

Open
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:gh-5340-locale-root-toUpperCase
Open

GH-5340: Use Locale.ROOT in toUpperCase calls for locale-neutral type normalization#6048
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:gh-5340-locale-root-toUpperCase

Conversation

@suryateja-g13
Copy link
Copy Markdown
Contributor

Problem

String.toUpperCase() without an explicit locale is locale-sensitive. On JVMs with a Turkish locale (tr_TR), it transforms integerİNTEGER and stringSTRİNG. This breaks Gemini tool calling because the API expects strict ASCII enum values (INTEGER, STRING, etc.), causing:

Invalid value at 'tools[0].function_declarations[1].parameters.properties[0].value.type' (type.googleapis.com/google.ai.generativelanguage.v1beta.Type), "İNTEGER"

Three call sites were affected:

  • JsonSchemaGenerator.convertTypeValuesToUpperCase() — used when building Gemini tool schemas
  • GoogleGenAiTrafficType.from() — used when parsing traffic type metadata
  • GoogleGenAiModalityTokenCount.convertModality() — used when parsing modality token count metadata

Fix

Replace .toUpperCase() with .toUpperCase(Locale.ROOT) at all three sites. Locale.ROOT is the correct choice for any case conversion that produces or compares protocol/API strings rather than user-visible text.

Test

Added JsonSchemaGeneratorTests#convertTypeValuesToUpperCaseIsLocaleNeutral which temporarily sets the JVM default locale to tr_TR, runs convertTypeValuesToUpperCase, and asserts that the resulting type values are plain ASCII uppercase (OBJECT, INTEGER, STRING).

Closes #5340

…le-neutral type normalization

String.toUpperCase() without a locale is locale-sensitive: on Turkish JVMs
(tr_TR) it converts 'integer' to 'İNTEGER', causing Gemini API validation
errors because the tool type schema expects strict ASCII enum values
(INTEGER, STRING, etc.).

Fix all three affected call sites to use toUpperCase(Locale.ROOT) and add
a unit test that verifies correctness under the Turkish locale.

Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
@suryateja-g13 suryateja-g13 force-pushed the gh-5340-locale-root-toUpperCase branch from 8e32bf0 to a14caba Compare May 17, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Locale-sensitive toUpperCase breaks Gemini tool type normalization (tr_TR → İNTEGER)

1 participant