Skip to content

Commit

Permalink
8295456: (ch) sun.nio.ch.Util::checkBufferPositionAligned gives misle…
Browse files Browse the repository at this point in the history
…ading/incorrect error

Reviewed-by: alanb
  • Loading branch information
Brian Burkhalter committed Oct 19, 2022
1 parent e27bea0 commit a5f6e31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/java.base/share/classes/sun/nio/ch/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,18 @@ static MappedByteBuffer newMappedByteBufferR(int size, long addr,
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) {
Expand All @@ -524,8 +523,7 @@ static void checkRemainingBufferSizeAligned(int rem,
}
}

static void checkChannelPositionAligned(long position,
int alignment)
static void checkChannelPositionAligned(long position, int alignment)
throws IOException
{
if (position % alignment != 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -144,7 +144,7 @@ private static void testWithNotAlignedBufferOffset() throws Exception {
fc.read(block);
throw new RuntimeException("Expected exception not thrown");
} catch (IOException e) {
if (!e.getMessage().contains("Current location of the bytebuffer "
if (!e.getMessage().contains("Current position of the bytebuffer "
+ "(" + pos + ") is not a multiple of the block size ("
+ alignment + ")"))
throw new Exception("Read test failed");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -101,7 +101,7 @@ private static void testWithNotAlignedBufferOffset() throws Exception {
fc.write(block);
throw new RuntimeException("Expected exception not thrown");
} catch (IOException e) {
if (!e.getMessage().contains("Current location of the bytebuffer "
if (!e.getMessage().contains("Current position of the bytebuffer "
+ "(" + pos + ") is not a multiple of the block size ("
+ alignment + ")"))
throw new Exception("Write test failed");
Expand Down

1 comment on commit a5f6e31

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.