8295456: (ch) sun.nio.ch.Util::checkBufferPositionAligned gives misleading/incorrect error

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2022-10-19 15:53:01 +00:00
parent e27bea0c4d
commit a5f6e31ccb
3 changed files with 11 additions and 13 deletions

View file

@ -502,19 +502,18 @@ public class Util {
return dbb;
}
static void checkBufferPositionAligned(ByteBuffer bb,
int pos, int alignment)
static void checkBufferPositionAligned(ByteBuffer bb, int pos, int alignment)
throws IOException
{
if (bb.alignmentOffset(pos, alignment) != 0) {
throw new IOException("Current location of the bytebuffer ("
final int alignmentOffset = bb.alignmentOffset(pos, alignment);
if (alignmentOffset != 0) {
throw new IOException("Current position of the bytebuffer ("
+ pos + ") is not a multiple of the block size ("
+ alignment + ")");
+ alignment + "): alignment offset = " + alignmentOffset);
}
}
static void checkRemainingBufferSizeAligned(int rem,
int alignment)
static void checkRemainingBufferSizeAligned(int rem, int alignment)
throws IOException
{
if (rem % alignment != 0) {
@ -524,8 +523,7 @@ public class Util {
}
}
static void checkChannelPositionAligned(long position,
int alignment)
static void checkChannelPositionAligned(long position, int alignment)
throws IOException
{
if (position % alignment != 0) {