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

JFileChooser - No Disk Dialog with RMISecurityManager

XMLWordPrintable

    • beta
    • x86
    • windows_nt, windows_2000



      Name: wl91122 Date: 08/23/99


      A program that installs the RMISecurityManager gets a modal dialog
       "There is no disk in the drive. Please insert a disk into drive a:" when
      instantiating a JFileChooser. Similar to closed bug 4147513, except
      that it is new to 1.2.2, and depends on installation of the
      RMISecurityManager. Code follows:

      public class TestFileChooser {
        public static void main(String[] args) {
          System.setSecurityManager(new java.rmi.RMISecurityManager());
          new javax.swing.JFileChooser();
        }
      }
      >java -version
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)
      >java -fullversion
      java full version "JDK-1.2.2-W"

      NT 4.0 tested with SP3 and SP4 showed same result.

      Bug 4219204 is clearly related in some way, but it is listed as closed,
      duplicate of 4089199, which in turn is listed as closed and will not be
      fixed! To reiterate, this bug is unique because

      1) It is specific to the RMISecurityManager (non RMI programs work fine)
      2) It is new to 1.2.2 (1.2.1 worked fine)
      3) It is specific to instantiation of the JFileChooser
      (Review ID: 85660)
      ======================================================================

      Name: krT82822 Date: 09/19/99


      When running an application which requires a Security Manager,
      such as an application that uses RMI, the Windows
      "No Disk in drive - Abort/Retry/Ignore" dialog is displayed
      when an attempt is made to display a JFileChooser.

      The following program demonstrates the problem. It must be used
      with a policy file which grants all permissions, such as the
      following:

      File "java.policy":

      grant {
        permission java.security.AllPermission;
      };


      File "JFileChooserTest.java":

      import javax.swing.*;

      public class JFileChooserTest
      {
          public static void main(String args[])
          {
              //
              // To use RMI we need to have a SecurityManager.
              // We will use the default SecurityManager for this
              // example.
              //
              System.setSecurityManager(new SecurityManager());

              //
              // Creating the chooser with different paths has no
              // effect. We'll try to display the C: drive...
              //
              JFileChooser chooser = new JFileChooser("c:\\");
              
              chooser.showDialog(new JFrame(), null);
              
              System.exit(0);
          }
      }

      To run the program:

      java -Djava.security.policy=file:.\java.policy JFileChooserTest


      The "Abort/Retry/Ignore" dialog is displayed and locks the UI.
      Once the dialog is dismissed, the JFileChooser is displayed.

      It is not acceptable to expect users to have to dismiss such
      dialogs every time they want to browse/load/save a file.

      Note: if the program is run with the installed default
      java.policy file, the "Abort/Retry/Ignore" dialog is displayed
      but an exception is thrown (java.security.AccessControlException)
      when the dialog is dismissed and the JFileChooser is not
      displayed.

      This problem occurs on:
      Platform: Win 95/98/NT 4.0(service pack 5)
      JVM: 1.2.2 (with and without HotSpot 1.0.1), 1.3 beta
      (Review ID: 95243)
      ======================================================================

      Name: rlT66838 Date: 11/08/99


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      On a Windows NT 4.0 machine that has an A: diskette drive:

      1. Remove any diskette from drive A:
      2. Compile the following Java 2 program using JDK 1.2.2:
      3. Run it.
      4. Notice that the first JFileChooser comes up without trouble.
      5. Dismiss the chooser by pressing cancel.
      6. The program then sets RMISecurityManager and tries again.
      7. Notice that this time, JFileChooser attempts to access drive A:, and gets the
      windows error dialog: "There is no disk in the drive. Please insert a disk into
      drive A:."
      8. If you press the Ignore button, the normal JFileChooser dialog comes up.

      Here's the Java Source Code:

      import java.io.File;
      import java.rmi.*;
      import javax.swing.*;

      /**
       * Demonstrates a bug where setting a security manager on Windows NT 4.0 causes
       * JFileChooser to attempt to access drive A: when dialog is shown, causing
      error dialog.
       */
      public class ShowChooserBug
      {
          public static void main(String[] args)
          {
              System.out.println("Make sure that you have no diskette in your A:
      drive.");
              System.out.println("Try #1 will work just fine...");

              tryChooser();

              System.out.println("Now setting system security manager...");
              
              Object curSecMgr = System.getSecurityManager();
              try
              {
                  if ((curSecMgr instanceof RMISecurityManager) == false)
                      System.setSecurityManager(new RMISecurityManager());
              }
              catch (SecurityException ex)
              {
                  ex.printStackTrace();
              }

              System.out.println("On Windows NT 4.0, our next try shows an evil dialog
      if no diskette in A...");

              tryChooser();

              System.exit(0);
          }

          public static void tryChooser()
          {
          JFileChooser jFileChooser = new JFileChooser();
              jFileChooser.showOpenDialog(JOptionPane.getRootFrame());
          }
      }

      This problem means that any program with an RMISecurityManager installed will
      not operate properly. If nothing else, can't you suppress the darn error
      message unless the user actually tries to navigate to the A: drive via the UI?
      This seems easy, and the current behavior looks very unprofessional in my
      application.
      (Review ID: 97617)
      ======================================================================

      Name: krT82822 Date: 12/15/99


      F:\JAVA\jdk1.2.2\bin>java.exe -version
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      If you comment out line 11 and run this code the dialog box appears and works
      fine.

      Leave in line 11 and run this piece of code and before the file chooser appears
      a dialog box appears saying that "There is no disk in drive. Please insert a
      disk into drive A:" and three buttons "Abort" "Retry" "Ignor". One you have
      dissmissed the error dialog box the file chooser works just fine.

      1 import java.rmi.*;
      2 import javax.swing.JFileChooser;
      3
      4 public class temp
      5 {
      6 public static void main(String args[])
      7 {
      8 if(System.getSecurityManager() == null)
      9 {
      10 System.out.println("getting a security manager");
      11 System.setSecurityManager(new RMISecurityManager());
      12 }
      13
      14 JFileChooser chooser = new JFileChooser();
      15 chooser.setMultiSelectionEnabled(false);
      16
      17 int returnVal = chooser.showSaveDialog(null);
      18
      19 System.exit(1);
      20 }
      21 }
      (Review ID: 99040)
      ======================================================================

      Name: skT45625 Date: 05/16/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-001, native threads, symcjit)

      JFileChooser try to access Drive A: on an NT4.0 machine when the
      SecurityManager is present and the policy is set to all. If the SecurityManager
      is not on then the JFileChooser dialog comes up normally. When it is on, a
      Insert Disk in Drive A: abort/retry/ignore dialog comes up before JFileChooser
      displays. Eventhought the initial directory is not set to drive A:. I actually
      traced the problem to File.listRoots() that turns around and call the native
      FileSystem.listRoots(). The problem thickens as that the behavior does not
      appear on all our NT machines...

      Here is a sample programs to illustrate

      public class FileChooserTest
      {
          public static void doThis( Frame f )
          {
            JFileChooser fc = new JFileChooser() ;
            int val = fc.showDialog( f, "Add" ) ;

            if ( val == JFileChooser.APPROVE_OPTION ) {
                 System.out.println( "Selected " + fc.getSelectedFile() ) ;
            }
          }
          
          public static void main( String[] args )
          {
              // Start Security Manager
             if ( System.getSecurityManager() == null )
      System.setSecurityManager( new java.rmi.RMISecurityManager() ) ;

             final JFrame f = new JFrame() ;

             JButton b = new JButton( "Hit Me!!" ) ;
              
             b.addActionListener( new AbstractAction()
              {
                  public void actionPerformed( ActionEvent evt )
                  {
                      doThis( f ) ;
                  }
              } ) ;
              
              f.getContentPane().add( "Center", b ) ;
              f.setSize( 300, 300 ) ;
              f.setVisible( true ) ;
           }
      }
      (Review ID: 104945)
      ======================================================================

            leifs Leif Samuelsson (Inactive)
            wleesunw William Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: