<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 11/02/2019 22:30, Brian Burkhalter wrote:<br>
<blockquote type="cite"
cite="mid:FA0C660F-CCB2-43A2-B8CF-F2BBBC8B3D02@oracle.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<br>
<div class="">The presence of the absolute index into the buffer
complicates the situation. In the absolute get() to an array,
for example, get(index,$type$[],offset,length) throwing a
BufferUnderflowException would make sense for</div>
<div class=""><br class="">
</div>
<div class="">0 <= index < limit() && index + length
> limit(),</div>
<div class=""><br class="">
</div>
<div class="">but if index < 0 or index > limit() an IOOBE
appears more logical. Likewise for
put(index,$type$[],offset,length), a BufferOverflowException
would work for</div>
<div class=""><br class="">
</div>
<div class="">0 <= index < limit() && index + length
> limit,</div>
<div class=""><br class="">
</div>
<div class="">but IOOBE again seems more apropos for index < 0
or index > limit(). For any given method where an IOOBE could
be thrown for different indexes being out of bounds, then a
better disambiguation message as Roger suggested would be
helpful. If an IOOBE can be thrown by only one particular index
being out of range, then the default checkFromIndexSize()
message might be enough. For example, for the code</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-stretch: normal; font-size: 11px;
line-height: normal; font-family: Menlo; background-color:
rgba(255, 255, 255, 0.811765);" class=""><span
style="font-variant-ligatures: no-common-ligatures" class="">Â
    byte[] ba = new byte[42];</span></div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px;
line-height: normal; font-family: Menlo; background-color:
rgba(255, 255, 255, 0.811765);" class="">Â Â Â Â bb.put(-1,
ba, 0, 42);</div>
</div>
<div class=""><span style="font-variant-ligatures:
no-common-ligatures" class=""><br class="">
</span></div>
<div class=""><span style="font-variant-ligatures:
no-common-ligatures" class="">the exception</span></div>
<div class=""><span style="font-variant-ligatures:
no-common-ligatures" class=""><br class="">
</span></div>
<div class=""><span style="font-variant-ligatures:
no-common-ligatures" class="">
<div style="margin: 0px; font-stretch: normal; font-size:
11px; line-height: normal; font-family: Menlo;
background-color: rgba(255, 255, 255, 0.811765);" class=""><span
style="font-variant-ligatures: no-common-ligatures"
class="">java.lang.IndexOutOfBoundsException: Range [-1,
-1 + 42) out of bounds for length 42</span></div>
</span></div>
<div class=""><span style="font-variant-ligatures:
no-common-ligatures" class=""><br class="">
</span></div>
<div class=""><span style="font-variant-ligatures:
no-common-ligatures" class="">is thrown which looks to be
sufficient if we know a priori which index is involved.</span></div>
<div class=""><br class="">
</div>
<div class="">For the method put(index,$Type$Buffer,offset,length)
the BufferUnderflowException would be for ‘src’ not having
enough elements to copy to ‘this’ and the
BufferOverflowException for ‘this’ not having enough space
before limit() to contain the copied elements. Again, either
‘index’ or ‘offset’ being out of range would be better handled
by an IOOBE.</div>
<div class=""><br class="">
</div>
<div class="">Note that using Buffer*flowException would require
an update to the specifications of these exceptions as now they
are described as being specific to relative operations.</div>
<br>
</blockquote>
I think you are on the right track with this thinking. That is,
throw IOOBE when index is negative or >= limit, throw the
Buffer*flowExceptions if the transfer would result in buffer
overflow/underflow. I think that will fix the inconsistency with the
current proposal and also helps with the troubleshooting a bit. Yes,
it does mean a small adjustment to the wording in the exceptions.<br>
<br>
-Alan<br>
</body>
</html>