Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4221505

(docs) java.io.FileInputStream.FileInputStream(FileDescriptor) acts not as doc s

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5



      Name: saC57035 Date: 03/18/99


      Javadoc specs for FileInputStream.FileInputStream(FileDescriptor) state:
            First, if there is a security manager, its checkRead method is called
            with the file descriptor fdObj as its argument to see if it's ok to
            read the file descriptor.

      However, in JDK 1.2.1 this method checks if fdObj is null at first.

      Here's an excerpt from the source code:
      -----------------------------------------------------------------
          public FileInputStream(FileDescriptor fdObj) {
              SecurityManager security = System.getSecurityManager();
              if (fdObj == null) {
                  throw new NullPointerException();
              }
              if (security != null) {
                  security.checkRead(fdObj);
              }
              fd = fdObj;
          }
      -----------------------------------------------------------------

      Here is an example demonstrating this bug

      ------------ Test.java --------------------------------------
      import java.io.*;

      public class Test {
          public static void main(String[] args) {
              FileDescriptor fdObj = null;
              try {
                  System.setSecurityManager(new SecurityManager());
              } catch (SecurityException e) {
                  System.out.println("Unable to install SecurityManager");
                  return;
              }
              try {
                  System.getSecurityManager().checkRead(fdObj);
              } catch (SecurityException e) {
                  System.out.println("Installed SecurityManager disables read access");
              } catch (NullPointerException e) {
                  System.out.println("Installed SecurityManager throws NullPointerException too");
                  return;
              }
              try {
                  FileInputStream fis = new FileInputStream(fdObj);
              } catch (SecurityException e) {
                  System.out.println("There is no error - SecurityException thrown");
              } catch (NullPointerException e) {
                  System.out.println("There is an error - NullPointerException thrown");
                  return;
              }
              System.out.println("There is an error - Exception was not thrown");
          }
      }
      ------------- Output ----------------------------------------
      Installed SecurityManager disables read access
      There is an error - NullPointerException thrown
      -----------------------------------------------------------------

      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            savzan Stanislav Avzan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: