<div dir="ltr"><p>Hello,</p>
<p>I would like to report a potential design issue in the JDK 25 implementation of <code>MessageFormat</code>.</p>
<p>While working with <code>java.util.Locale#getDisplayName()</code>, I found that JDK internals throw and catch an <code>IllegalArgumentException</code> due to the following pattern added in the resource bundles:</p>
<ul>
<li>
<p><code>sun.util.resources.cldr.LocaleNames</code></p>
</li>
<li>
<p><code>sun.util.resources.LocaleNames</code></p>
</li>
</ul>
<p>The pattern in question is:</p>
<pre class="gmail-overflow-visible! gmail-px-0!"><div class="gmail-contain-inline-size gmail-rounded-2xl gmail-corner-superellipse/1.1 gmail-relative gmail-bg-token-sidebar-surface-primary"><div class="gmail-sticky gmail-top-9"><div class="gmail-absolute end-0 gmail-bottom-0 gmail-flex gmail-h-9 gmail-items-center gmail-pe-2"><div class="gmail-bg-token-bg-elevated-secondary gmail-text-token-text-secondary gmail-flex gmail-items-center gmail-gap-4 gmail-rounded-sm gmail-px-2 gmail-font-sans gmail-text-xs"></div></div></div><div class="gmail-overflow-y-auto gmail-p-4" dir="ltr"><code class="gmail-whitespace-pre!"><span class="gmail-hljs-attr">DisplayNamePattern:</span> {<span class="gmail-hljs-number">0</span>,<span class="gmail-hljs-string">choice</span>,<span class="gmail-hljs-number">0</span><span class="gmail-hljs-comment">#|1#{1}|2#{1} ({2})}</span>
</code></div></div></pre>
<p>This change originates from the following commit:<br>
<code>adoptium/jdk@00ffc42</code> â€” which adds a pattern for <code>MessageFormat</code>.<br>
However, <code>choice</code> is <strong>not</strong> a valid type for <code>FormatStyle</code>.</p>
<p>As a result, calling <code>Locale#getDisplayName()</code> triggers the following exception inside JDK code:</p>
<pre class="gmail-overflow-visible! gmail-px-0!"><div class="gmail-contain-inline-size gmail-rounded-2xl gmail-corner-superellipse/1.1 gmail-relative gmail-bg-token-sidebar-surface-primary"><div class="gmail-sticky gmail-top-9"><div class="gmail-absolute end-0 gmail-bottom-0 gmail-flex gmail-h-9 gmail-items-center gmail-pe-2"><div class="gmail-bg-token-bg-elevated-secondary gmail-text-token-text-secondary gmail-flex gmail-items-center gmail-gap-4 gmail-rounded-sm gmail-px-2 gmail-font-sans gmail-text-xs"></div></div></div><div class="gmail-overflow-y-auto gmail-p-4" dir="ltr"><code class="gmail-whitespace-pre!">java.lang.IllegalArgumentException
    at java.base/java.text.MessageFormat<span class="gmail-hljs-variable">$FormatStyle</span>.fromString(MessageFormat.java:2013)
    at java.base/java.text.MessageFormat.formatFromPattern(MessageFormat.java:1718)
    at java.base/java.text.MessageFormat.setFormatFromPattern(MessageFormat.java:1679)
    at java.base/java.text.MessageFormat.applyPatternImpl(MessageFormat.java:660)
    at java.base/java.text.MessageFormat.<init>(MessageFormat.java:516)
    at java.base/java.util.Locale.getDisplayName(Locale.java:2309)
</code></div></div></pre>
<p>The implementation currently relies on exception-based logic:</p>
<pre class="gmail-overflow-visible! gmail-px-0!"><div class="gmail-contain-inline-size gmail-rounded-2xl gmail-corner-superellipse/1.1 gmail-relative gmail-bg-token-sidebar-surface-primary"><div class="gmail-sticky gmail-top-9"><div class="gmail-absolute end-0 gmail-bottom-0 gmail-flex gmail-h-9 gmail-items-center gmail-pe-2"><div class="gmail-bg-token-bg-elevated-secondary gmail-text-token-text-secondary gmail-flex gmail-items-center gmail-gap-4 gmail-rounded-sm gmail-px-2 gmail-font-sans gmail-text-xs"></div></div></div><div class="gmail-overflow-y-auto gmail-p-4" dir="ltr"><code class="gmail-whitespace-pre! gmail-language-java"><span class="gmail-hljs-keyword">try</span> {
    fStyle = FormatStyle.fromString(style);
} <span class="gmail-hljs-keyword">catch</span> (IllegalArgumentException iae) {
    fStyle = FormatStyle.SUBFORMATPATTERN;
}
</code></div></div></pre>
<p>I understand that <code>MessageFormat</code> catches this exception and falls back to <code>SUBFORMATPATTERN</code>, but using exceptions to control expected logic paths may not be ideal—especially since <code>FormatStyle.fromString()</code> is only used by <code>MessageFormat</code>.</p>
<p>A potentially cleaner approach could be to have <code>FormatStyle.fromString()</code> return <code>FormatStyle.SUBFORMATPATTERN</code> directly when encountering unknown style identifiers, instead of throwing an exception.</p>
<p><strong>JDK Version Observed:</strong></p>
<pre class="gmail-overflow-visible! gmail-px-0!"><div class="gmail-contain-inline-size gmail-rounded-2xl gmail-corner-superellipse/1.1 gmail-relative gmail-bg-token-sidebar-surface-primary"><div class="gmail-sticky gmail-top-9"><div class="gmail-absolute end-0 gmail-bottom-0 gmail-flex gmail-h-9 gmail-items-center gmail-pe-2"><div class="gmail-bg-token-bg-elevated-secondary gmail-text-token-text-secondary gmail-flex gmail-items-center gmail-gap-4 gmail-rounded-sm gmail-px-2 gmail-font-sans gmail-text-xs"></div></div></div><div class="gmail-overflow-y-auto gmail-p-4" dir="ltr"><code class="gmail-whitespace-pre!">OpenJDK Runtime Environment Temurin-<span class="gmail-hljs-number">25.0</span><span class="gmail-hljs-selector-class">.1</span>+<span class="gmail-hljs-number">8</span> (build <span class="gmail-hljs-number">25.0</span>.<span class="gmail-hljs-number">1</span>+<span class="gmail-hljs-number">8</span>-LTS)
</code></div></div></pre>
<p>Please let me know if this behavior is intentional, or if it should be considered for improvement.</p>
<p>Best regards,<br>
vincent gao</p></div>