<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello Lee, for context, I believe this was changed in <a href="https://bugs.openjdk.org/browse/JDK-8321387">
https://bugs.openjdk.org/browse/JDK-8321387</a></div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
So this was mainly because in the implementation, the access methods aren't operating on the segment, but rather using the VarHandles - this means that those VarHandle may be passed either readOnly or modifiable segments, and they had been made to throw IAE
instead of UOE, which was more correct.</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In addition, when you encounter this exception, usually you are working on a MS passed from parameters instead of one you allocated on your own - this is also an argument for IAE (for untrusted segments) instead of UOE (for trusted segments, you should have
taken care at writing code or running tests).</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Also, do not rely on the behavior of preview features, which FFM was back in 21 - these features are not subject to backward compatibility in future releases, and this thrown exception change was done under this consideration.</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div class="elementToProof" style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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> panama-dev <panama-dev-retn@openjdk.org> on behalf of Lee Rhodes <leerho@gmail.com><br>
<b>Sent:</b> Saturday, April 26, 2025 2:31 PM<br>
<b>To:</b> panama-dev@openjdk.org <panama-dev@openjdk.org><br>
<b>Subject:</b> Exception change? and Reason?</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>In Java 21 FFM, attempting a write operation on a MemorySegment configured as ReadOnly throws a <i>UnsupportedOperationException (UOE),</i> which makes sense.</div>
<div><br>
</div>
<div>However, starting with Java 22, FFM, attempting a write operation on a MemorySegment configured as ReadOnly throws a <i>IllegalArgumentException (IAE),</i> which makes less sense to me. </div>
<div><br>
</div>
<div>I guess you could argue it either way, but one could look at it this way:</div>
<div>
<ul>
<li>The target is correct, but the operation is incorrect -- thus, UOE makes sense </li><li>The target of the operation is incorrect, but the operation is correct -- thus, IAE makes sense</li><li>The target is correct and the operation is correct, but the target is incorrectly configured as read-only -- thus UOE makes sense</li><li>Both the target and the operation are incorrect -- thus, either UOE or IAE could make sense.</li></ul>
</div>
<div>Of these 4 cases, I would think the first 3 are the most common, in which case the UOE would be the most likely cause.</div>
<div><br>
</div>
<div>I'm sure the Java authors must have a more eloquent reason why this was changed, and I tried to find release notes that would explain this change but to no avail.</div>
<div><br>
</div>
<div>Please enlighten me.</div>
<div><br>
</div>
<div>Lee.</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</body>
</html>