src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java

Print this page
rev 11066 : 8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
Summary: FileKey.create() should throw an IOException directly instead of wrapping it in an Error.
Reviewed-by: TBD


  92         this.nd = new FileDispatcherImpl();
  93     }
  94 
  95     // Used by FileInputStream.getChannel(), FileOutputStream.getChannel
  96     // and RandomAccessFile.getChannel()
  97     public static FileChannel open(FileDescriptor fd, String path,
  98                                    boolean readable, boolean writable,
  99                                    Object parent)
 100     {
 101         return new FileChannelImpl(fd, path, readable, writable, parent);
 102     }
 103 
 104     private void ensureOpen() throws IOException {
 105         if (!isOpen())
 106             throw new ClosedChannelException();
 107     }
 108 
 109     // -- Standard channel operations --
 110 
 111     protected void implCloseChannel() throws IOException {



 112         // Release and invalidate any locks that we still hold
 113         if (fileLockTable != null) {
 114             for (FileLock fl: fileLockTable.removeAll()) {
 115                 synchronized (fl) {
 116                     if (fl.isValid()) {
 117                         nd.release(fd, fl.position(), fl.size());
 118                         ((FileLockImpl)fl).invalidate();
 119                     }
 120                 }
 121             }
 122         }
 123 
 124         // signal any threads blocked on this channel
 125         threads.signalAndWait();
 126 
 127         if (parent != null) {
 128 
 129             // Close the fd via the parent stream's close method.  The parent
 130             // will reinvoke our close method, which is defined in the
 131             // superclass AbstractInterruptibleChannel, but the isOpen logic in




  92         this.nd = new FileDispatcherImpl();
  93     }
  94 
  95     // Used by FileInputStream.getChannel(), FileOutputStream.getChannel
  96     // and RandomAccessFile.getChannel()
  97     public static FileChannel open(FileDescriptor fd, String path,
  98                                    boolean readable, boolean writable,
  99                                    Object parent)
 100     {
 101         return new FileChannelImpl(fd, path, readable, writable, parent);
 102     }
 103 
 104     private void ensureOpen() throws IOException {
 105         if (!isOpen())
 106             throw new ClosedChannelException();
 107     }
 108 
 109     // -- Standard channel operations --
 110 
 111     protected void implCloseChannel() throws IOException {
 112         if (!fd.valid())
 113             return; // nothing to do
 114 
 115         // Release and invalidate any locks that we still hold
 116         if (fileLockTable != null) {
 117             for (FileLock fl: fileLockTable.removeAll()) {
 118                 synchronized (fl) {
 119                     if (fl.isValid()) {
 120                         nd.release(fd, fl.position(), fl.size());
 121                         ((FileLockImpl)fl).invalidate();
 122                     }
 123                 }
 124             }
 125         }
 126 
 127         // signal any threads blocked on this channel
 128         threads.signalAndWait();
 129 
 130         if (parent != null) {
 131 
 132             // Close the fd via the parent stream's close method.  The parent
 133             // will reinvoke our close method, which is defined in the
 134             // superclass AbstractInterruptibleChannel, but the isOpen logic in