Skip to content

Bug: Turkish Locale - Potential Header/Key resolution failure due to case-insensitive TreeMap serialization #755

Closed as not planned

Description

@yalcinmuhammed

Bug Description

Applications utilizing this SDK on a Turkish OS locale face unexpected anomalies or token crashes during HTTP header parsing.

Root Cause

In openai-java-core/src/main/kotlin/com/openai/core/http/Headers.kt (Line 38), the headers map is initialized using a locale-dependent comparison mechanism:

private val map: MutableMap<String, MutableList<String>> =
    TreeMap(String.CASE_INSENSITIVE_ORDER)

Java's native String.CASE_INSENSITIVE_ORDER internally triggers Character.toLowerCase(). On a Turkish host machine, this converts the capital letter I in "OpenAI-Organization" into a dotless ı, turning it into "openaı-organization".
This causes key lookup failures or broken token states when downstream interceptors (like OkHttp) process standard ASCII headers.

Related Upstream Issue

This is the Java/Kotlin ecosystem equivalent of the localization bug found in the Node SDK.

Suggested Official Fix

The TreeMap should enforce a locale-invariant comparator (such as Locale.ROOT) to guarantee strict ASCII/English-based casing rules across all operating systems:

TreeMap { s1, s2 -> s1.lowercase(java.util.Locale.ROOT).compareTo(s2.lowercase(java.util.Locale.ROOT)) }

Activity

  1. arimu1 commented on Jul 25, 2026

    @arimu1

    I opened and then closed #817 after verifying the premise.

    TreeMap(String.CASE_INSENSITIVE_ORDER) is not affected by Turkish locale: the comparator uses Unicode case mapping (Character.toUpperCase/toLowerCase), not String.toLowerCase(). Under Locale("tr","TR"), header keys still match across case.

    Turkish dotted/dotless I only bites locale-sensitive String case folding. Happy to help if there is a different repro (e.g. a code path that lowercases header names with the default locale).

  2. dpiet-oai commented on Sep 30, 2026

    @dpiet-oai
    Contributor

    Thanks for the report and for the follow-up verification above. We could not reproduce the reported behavior.

    An offline Java check under the Turkish default locale tr-TR passed case-insensitive lookup, replacement, and removal for OpenAI-Organization and OpenAI-Project using TreeMap(String.CASE_INSENSITIVE_ORDER). The stored header names retained their original spelling, and String.CASE_INSENSITIVE_ORDER.compare("I", "i") returned 0.

    String.CASE_INSENSITIVE_ORDER uses locale-independent character folding via Character.toUpperCase and Character.toLowerCase. It does not use the default-locale conversion performed by String.toLowerCase(), and comparing keys does not rewrite them. See the Java documentation. This agrees with the earlier reproduction comment and the verification that led to closing #817.

    Closing as not reproducible as described. If the failure occurs through another path, please share a minimal runnable example, the SDK and JDK versions, and the exception or failing request details with credentials removed. We can reopen and investigate that example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions