EVALUATION
I believe that a similar problem will be observed with X-Buffer.asReadOnlyBuffer
when the buffer isn't read-only.
From the spec of ByteBuffer.duplicate:
The new buffer's capacity, limit, position, and mark values will be
identical to those of this buffer.
When calling ByteBuffer.duplicate, we eventually end up calling the
package-private constructor in Buffer.java.
From the Buffer.java class javadoc:
The following invariant holds for the mark, position, limit, and capacity
values:
0 <= mark <= position <= limit <= capacity
A newly-created buffer always has a position of zero and a mark that is
undefined.
It looks like a minor modification is needed to the constructor in Buffer.java
to handle the case of mark == 0:
Buffer(int mark, int pos, int lim, int cap) {
[ ... ]
if (mark > 0) { // change to (mark >= 0)
if (mark > pos)
throw new IllegalArgumentException();
this.mark = mark;
}
}
I don't believe that 0 is ever used in the buffer code to indicate an error
condition or an unset mark, but close examination of all of the code in
java.nio.*Buffer* should be made before this change is applied.
###@###.### 2005-2-22 21:12:25 GMT
|