-
Bug
-
Resolution: Fixed
-
P3
-
20, 21, 22
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8331426 | 22u-cpu | Weibing Xiao | P3 | Resolved | Fixed | master |
JDK-8331294 | 21.0.5-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8333414 | 21.0.5 | Martin Doerr | P3 | Resolved | Fixed | b01 |
ADDITIONAL SYSTEM INFORMATION :
JRE 21.0.2+13
A DESCRIPTION OF THE PROBLEM :
The Javadoc states, "If the given position is greater than or equal to the file's current size then no bytes are transferred." The below exception happens when the position equals the current size.
IOException: Channel not open for writing - cannot extend file to required size
at java.base/sun.nio.ch.FileChannelImpl.mapInternal(FileChannelImpl.java:1282)
at java.base/sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:1183)
at java.base/sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:676)
at java.base/sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:782)
REGRESSION : Last worked in version 17.0.10
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a file of any length
2. Attempt to copy bytes from that file to another file using FileChannel transferTo where:
* position is equal to the size of the original file
* count is greater than MAPPED_TRANSFER_SIZE of 16384
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception. No bytes are transferred as stated in the Javadoc.
ACTUAL -
IOException: Channel not open for writing - cannot extend file to required size
---------- BEGIN SOURCE ----------
@Test
public void test() throws Exception {
final Path parent = tempFolder.toPath();
final File original = parent.resolve("original").toFile();
try (PrintWriter out = new PrintWriter(original)) {
out.println("test");
}
final File copy = parent.resolve("copy").toFile();
try (FileInputStream in = new FileInputStream(original);
FileOutputStream out = new FileOutputStream(copy);
FileChannel inChannel = in.getChannel();
FileChannel outChannel = out.getChannel()) {
inChannel.transferTo(original.length(), 16385, outChannel);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Avoid calling FileChannel transferTo with a position equal to the size of the channel. The call is unnecessary but breaks code that is implemented in accordance to the Javadoc.
FREQUENCY : always
JRE 21.0.2+13
A DESCRIPTION OF THE PROBLEM :
The Javadoc states, "If the given position is greater than or equal to the file's current size then no bytes are transferred." The below exception happens when the position equals the current size.
IOException: Channel not open for writing - cannot extend file to required size
at java.base/sun.nio.ch.FileChannelImpl.mapInternal(FileChannelImpl.java:1282)
at java.base/sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:1183)
at java.base/sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:676)
at java.base/sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:782)
REGRESSION : Last worked in version 17.0.10
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a file of any length
2. Attempt to copy bytes from that file to another file using FileChannel transferTo where:
* position is equal to the size of the original file
* count is greater than MAPPED_TRANSFER_SIZE of 16384
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception. No bytes are transferred as stated in the Javadoc.
ACTUAL -
IOException: Channel not open for writing - cannot extend file to required size
---------- BEGIN SOURCE ----------
@Test
public void test() throws Exception {
final Path parent = tempFolder.toPath();
final File original = parent.resolve("original").toFile();
try (PrintWriter out = new PrintWriter(original)) {
out.println("test");
}
final File copy = parent.resolve("copy").toFile();
try (FileInputStream in = new FileInputStream(original);
FileOutputStream out = new FileOutputStream(copy);
FileChannel inChannel = in.getChannel();
FileChannel outChannel = out.getChannel()) {
inChannel.transferTo(original.length(), 16385, outChannel);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Avoid calling FileChannel transferTo with a position equal to the size of the channel. The call is unnecessary but breaks code that is implemented in accordance to the Javadoc.
FREQUENCY : always
- backported by
-
JDK-8331294 (fc) FileChannel.transferTo throws IOException when position equals size
- Resolved
-
JDK-8331426 (fc) FileChannel.transferTo throws IOException when position equals size
- Resolved
-
JDK-8333414 (fc) FileChannel.transferTo throws IOException when position equals size
- Resolved
- links to
-
Commit openjdk/jdk21u-dev/e4ac1a44
-
Commit openjdk/jdk/6b7c9718
-
Review openjdk/jdk21u-dev/631
-
Review openjdk/jdk/17796
(2 links to)