<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hey Tagir, we were discussing this internally a couple months ago, and I felt there was a general consensus that this is indeed a spec bug. Javac's permissiveness seems totally reasonable here.</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
We either need to insert more WRCs before unbox conversions (like the one you found), or (a seemingly-simpler approach that I hope will work) just tweak the specification of unboxing conversion itself so it applies to any
<i>subtype</i> of Integer-etc., instead of only the exact type. (Of course this also affects intersection types and capture types as well as the case in your example.)</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
We didn't jump on fixing it yet but it's slated to happen sooner or later as part of a series of type-conversion cleanups we're working on. Hopefully just getting this answer unblocks you for now?</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div dir="ltr" style="font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="mail-editor-reference-message-container">
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"></div>
<div class="ms-outlook-mobile-reference-message skipProofing" style="text-align: left; padding: 3pt 0in 0in; border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) currentcolor currentcolor; font-family: Aptos; font-size: 12pt; color: black;">
<b><br>
<p style="font-family:Calibri;font-size:10pt;color:#000000;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
Confidential- Oracle Internal<br>
</p>
From: </b>compiler-dev <compiler-dev-retn@openjdk.org> on behalf of Tagir Valeev <amaembo@gmail.com><br>
<b>Date: </b>Monday, December 15, 2025 at 9:21 AM<br>
<b>To: </b>compiler-dev@openjdk.org <compiler-dev@openjdk.org><br>
<b>Subject: </b>Unboxing conversion of generic types with box as a bound<br>
<br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Hello!</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">I noticed that the following program is compilable without errors using OpenJDK 25 javac:</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">private static <X extends Integer> void add(X x) {<br>
System.out.println(+x);<br>
}<br>
<br>
void main() {<br>
add(10);<br>
}</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">I wonder if it's correct. The JLS 15.15.3 says [1]:</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
The type of the operand expression of the unary + operator must be a type that is convertible (§5.1.8) to a primitive numeric type, or a compile-time error occurs.<br>
<br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">The JLS 5.1.8, in turn, says [2]:</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Unboxing conversion treats expressions of a reference type as expressions of a corresponding primitive type. Specifically, the following eight conversions are called the unboxing conversions:<br>
...</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">From type Integer to type int<br>
...</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">At run time, unboxing conversion proceeds as follows:</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">...</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">If r is a reference of type Integer, then unboxing conversion converts r into r.intValue()<br>
<br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">In my case, the type of reference is X, rather than Integer. So my question, should I read 'type Integer' here as 'type Integer, or any generic type whose upper bound is type Integer'?
In other words, should we assume that the X type declared as `X extends Integer` is convertible to a primitive numeric type? It looks like, here a widening reference conversion (5.1.5) happens before an unboxing conversion, but 15.15.3 does not say about widening
reference conversion. I've also checked 5.6 "Numeric contexts", but it also does not mention that before unboxing conversion, a widening reference conversion might occur. </div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Could anybody please clarify whether the compiler is wrong or I read the specification incorrectly? Thank you in advance!</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">With best regards,</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">Tagir Valeev</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing"><br>
</div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">[1] <a href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.15.3" data-outlook-id="343245d0-98d3-4fc9-bba2-3e18f6a7958d">
https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.15.3</a></div>
<div dir="ltr" class="ms-outlook-mobile-reference-message skipProofing">[2] <a href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-5.html#jls-5.1.8" data-outlook-id="08f6c6bf-b8a3-4fbe-b31a-8e0ce40bad9e">
https://docs.oracle.com/javase/specs/jls/se25/html/jls-5.html#jls-5.1.8</a></div>
</div>
</body>
</html>