<div dir="ltr"><div dir="ltr">hi , because of ``<span style="font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(207,142,109)">private static </span><span style="font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(188,190,196)">FormatStyle </span><span style="font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(86,168,245)">fromString</span><span style="font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(188,190,196)">(String text)</span>` throw exception and the try catch exception just set the deault value `<span style="font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(188,190,196)">FormatStyle.</span><span style="font-family:"JetBrains Mono",monospace;font-size:9.8pt;background-color:rgb(30,31,34);color:rgb(199,125,187);font-style:italic">SUBFORMATPATTERN</span>` , so why just make this function retuen this value like ? Is it better , right ?</div><div dir="ltr">```</div><div dir="ltr"><div style="background-color:rgb(30,31,34);color:rgb(188,190,196)"><pre style="font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(207,142,109)">private static </span>FormatStyle <span style="color:rgb(86,168,245)">fromString</span>(String text) {<br> <span style="color:rgb(207,142,109)">for </span>(FormatStyle style : <span style="font-style:italic">values</span>()) {<br> <span style="color:rgb(122,126,133)">// Also check trimmed case-insensitive for historical reasons<br></span><span style="color:rgb(122,126,133)"> </span><span style="color:rgb(207,142,109)">if </span>(style != FormatStyle.<span style="color:rgb(199,125,187);font-style:italic">SUBFORMATPATTERN </span>&&<br> text.trim().compareToIgnoreCase(style.<span style="color:rgb(199,125,187)">text</span>) == <span style="color:rgb(42,172,184)">0</span>) {<br> <span style="color:rgb(207,142,109)">return </span>style;<br> }<br> }<br> <span style="color:rgb(207,142,109)">return </span>FormatStyle.<span style="color:rgb(199,125,187);font-style:italic">SUBFORMATPATTERN</span>;<br>}</pre></div></div><div dir="ltr">```</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">weigao <<a href="mailto:china.weigao@gmail.com">china.weigao@gmail.com</a>> 于2025年12月11日周四 11:21写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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><div><div><div><div></div></div></div><div dir="ltr"><code><span>DisplayNamePattern:</span> {<span>0</span>,<span>choice</span>,<span>0</span><span>#|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><div><div><div><div></div></div></div><div dir="ltr"><code>java.lang.IllegalArgumentException
at java.base/java.text.MessageFormat<span>$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><div><div><div><div></div></div></div><div dir="ltr"><code><span>try</span> {
fStyle = FormatStyle.fromString(style);
} <span>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><div><div><div><div></div></div></div><div dir="ltr"><code>OpenJDK Runtime Environment Temurin-<span>25.0</span><span>.1</span>+<span>8</span> (build <span>25.0</span>.<span>1</span>+<span>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>
</blockquote></div></div>