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

Some swing classes use Class.getResource() which causes security exceptions

XMLWordPrintable

    • swing1.0fcs
    • sparc
    • solaris_2.5.1
    • Verified



      Name: aaC67449 Date: 01/29/98



      Constructor ImageIcon(URL) throws strange Exception (AccessControlException:connect from mars to denied), when tries to get systemresource Image in secure environment (loading applet via http and appletviewer.security.mode=host). Thus some methods in swing classes do not work in this enviroment(see Example2).
      See also bug 4107761.


      -------------------Example-----------------------------------
      import java.awt.swing.*;
      import java.applet.*;
      import java.net.*;
      import java.awt.*;
      public class Test1 extends Applet {

        public void init() {

         URL url=UIManager.getLookAndFeel()
                              .getClass().getResource("icons/TreeClosed.gif");
         
         System.out.println("URL:"+url);

         ImageIcon i=new ImageIcon(url);

        }

      }

      -------------------Output------------------------------------
      #>grep appletviewer.security.mode ~/.hotjava/properties
      appletviewer.security.mode=host
      #>appletviewer http://mars:8080/~ali/test1.html
      URL:systemresource:/ZIP/set/java/JDK1.2-Beta3D/solaris/lib/classes.zip/+/java/awt/swing/motif/icons/TreeClosed.gif
      java.security.AccessControlException: connect from mars to denied
              at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:337)
              at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:390)
              at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:278)
              at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:89)
              at sun.awt.SunToolkit.getImage(SunToolkit.java:123)
              at Test1.init(Test1.java:14)
              at sun.applet.AppletPanel.run(AppletPanel.java:283)
              at java.lang.Thread.run(Thread.java:490)
      ^C

      # another case
      #>grep appletviewer.security.mode ~/.hotjava/properties
      appletviewer.security.mode=unrestricted
      #>appletviewer http://mars:8080/~ali/test1.html
      URL:systemresource:/ZIP/set/java/JDK1.2-Beta3D/solaris/lib/classes.zip/+/java/awt/swing/motif/icons/TreeClosed.gif
      ^C

      -------------------Example2-----------------------------------
      import java.awt.swing.*;
      import java.applet.*;
      public class Test2 extends Applet {

        public void init() {
          JInternalFrame f=new JInternalFrame();
          JDesktopPane p=new JDesktopPane();
          p.add(f);
          f.setMaximizable(true);
          try {
           f.setMaximum(true);
          } catch(Exception e) {
             System.out.println("Unexpected:"+e);
          }
          
          try {
               JDesktopIcon i=new JDesktopIcon(f);
          } catch(Exception e) {
               System.out.println("Unexpected:"+e);
          }
        
       }

      }

      -------------------Output------------------------------------

      #>grep appletviewer.security.mode ~/.hotjava/properties
      appletviewer.security.mode=host
      #>appletviewer http://mars:8080/~ali/test2.html
      failed creating java.awt.swing.motif.MotifLookAndFeel$1@9a233cd (key=DesktopIcon.icon)
      Unexpected:java.lang.NullPointerException
      failed creating java.awt.swing.motif.MotifLookAndFeel$1@9a233cd (key=DesktopIcon.icon)
      Unexpected:java.lang.NullPointerException
      ^C
      # another case
      #>grep appletviewer.security.mode ~/.hotjava/properties
      appletviewer.security.mode=unrestricted
      #>appletviewer http://mars:8080/~ali/test2.html
      ^C

      ======================================================================
      ---------------------------------------------------------
      The problem seems to be addressed in JDK-1.2beta3-F.
      However the Example2 from the bug report still fails.

      The appletviewer reports AccessControlException (not NullPointerException as earlier):

      % appletviewer http://mars:8080/~gor/gor/bugs/test2.html
      Unexpected:java.security.AccessControlException: access denied (java.io.FilePermission /set/java/JDK1.2-Beta3F/solaris/lib/classes.zip read)
      Unexpected:java.security.AccessControlException: access denied (java.io.FilePermission /set/java/JDK1.2-Beta3F/solaris/lib/classes.zip read)

      Could you please clarify in which JDK1.2 build this problem is supposed to be fixed.
      ---------------------------------------------------------

      ###@###.### 1998-02-11

            rupashka Pavel Porvatov (Inactive)
            aalievsunw Artem Aliev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: