<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hello Vincent Gao,</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
I saw your Java Bugs submission. Unfortunately your stacktrace caused some confusion to our triage because it is an internal exception and that trace is never printed anywhere.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Your suggestion is a reasonable enhancement, that we should not use ad-hoc exceptions for control flow, given they need to fill stack traces, which is extremely costly.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Since this is a cleanup, we might commit this to mainline JDK first. If this proves to be a performance bottleneck on 25 updates, we can backport.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Since you are writing here, I assume this has a non-negligible impact on performance.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
If you can share a flame graph showing the regression from this exception, or a benchmark difference between 21 and 25.0.1, this would be extremely helpful.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Regards,</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Chen Liang</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of weigao <china.weigao@gmail.com><br>
<b>Sent:</b> Wednesday, December 10, 2025 9:31 PM<br>
<b>To:</b> core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Re: [External] Feedback JDK-8318761 : Potential Issue in JDK 25 MessageFormat: Use of Internal Exception for Control Flow</font>
<div> </div>
</div>
<div>
<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="x_gmail_quote x_gmail_quote_container">
<div dir="ltr" class="x_gmail_attr">weigao <<a href="mailto:china.weigao@gmail.com">china.weigao@gmail.com</a>> 于2025年12月11日周四 11:21写道:<br>
</div>
<blockquote class="x_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>
</div>
</body>
</html>