diff --git a/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java b/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java index d203910bf8c..4aeafa2b460 100644 --- a/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java +++ b/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2023, 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 @@ -25,6 +25,7 @@ package sun.nio.ch; +import java.io.Closeable; import java.io.FileDescriptor; import java.io.IOException; import java.io.UncheckedIOException; @@ -79,7 +80,7 @@ public class FileChannelImpl private final boolean readable; // Required to prevent finalization of creating stream (immutable) - private final Object parent; + private final Closeable parent; // The path of the referenced file // (null if the parent stream is created with a file descriptor) @@ -121,7 +122,7 @@ public class FileChannelImpl } private FileChannelImpl(FileDescriptor fd, String path, boolean readable, - boolean writable, boolean direct, Object parent) + boolean writable, boolean direct, Closeable parent) { this.fd = fd; this.path = path; @@ -149,7 +150,7 @@ public class FileChannelImpl // and RandomAccessFile::getChannel public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, - boolean direct, Object parent) + boolean direct, Closeable parent) { return new FileChannelImpl(fd, path, readable, writable, direct, parent); } @@ -193,25 +194,24 @@ public class FileChannelImpl threads.signalAndWait(); if (parent != null) { - + // // Close the fd via the parent stream's close method. The parent // will reinvoke our close method, which is defined in the // superclass AbstractInterruptibleChannel, but the isOpen logic in // that method will prevent this method from being reinvoked. // - ((java.io.Closeable)parent).close(); - } else if (closer != null) { + parent.close(); + } else { // parent == null hence closer != null + // // Perform the cleaning action so it is not redone when // this channel becomes phantom reachable. + // try { closer.clean(); } catch (UncheckedIOException uioe) { throw uioe.getCause(); } - } else { - fdAccess.close(fd); } - } public int read(ByteBuffer dst) throws IOException {