United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6594219 Plugin loads Swing classes
JDK-6594219 : Plugin loads Swing classes

Details
Type:
Bug
Submit Date:
2007-08-17
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2010-07-06
Component:
deploy
OS:
generic,windows_xp
Sub-Component:
plugin
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6,6u10,7
Fixed Versions:

Related Reports
Backport:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

Description
Java plugin loads many Swing classes even if the applet does not use Swing, and Java console is off.

I configured plugin to run hprof (-Xrunhprof:heap=dump), and set 'Do not start console' in Advanced/Java console. Though my applet was AWT-only, 66 Swing classes were loaded - see attached hprof.txt.

I used Firefox2 and JDK 7 b17 on Linux, and the following applet:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class T extends Applet {
    public void start() {
        final Frame f = new Frame("100% AWT");
        f.add(new Button("Hit me if you can!"));
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent ev) {
                System.out.println("Exiting!");
                f.setVisible(false);
                f.dispose();
            }
        });
        
        f.pack();
        f.setVisible(true);
    }
}

                                    

Comments
EVALUATION

This is the thread that most likely triggers loading Swing classes (JDK7 b17):
	com.sun.deploy.util.DeployUIManager.setLookAndFeel(DeployUIManager.java:84)
	sun.plugin.util.PluginSysUtil$1.run(PluginSysUtil.java:66)
	java.lang.Thread.run(Thread.java:644)
                                     
2007-08-29
EVALUATION

There's a way to specify the default LAF Swing will use, without having to load Swing classes. It is, to set the "swing.defaultlaf" property:
  System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.motif.MotifLookAndFeel");

Unfortunately getting system LAF name from Swing would need UIManager to be loaded :(  You may want to borrow some logic from UIManager.getSystemLookAndFeelClassName().
                                     
2007-09-19
EVALUATION

There are several places where Swing classes are loaded. They were identified by running ArcTest applet - pure AWT - inside plugin on Windows.

The first problem is described above: DeployUIManager.setLookAndFeel(). This method can be rewritten to set system property "swing.defaultlaf" instead of setting LAF directly. Code that guesses system LAF should be copied from UIManager.

This method also puts current Metal theme name into themeMap. This map now seems unused. It was previously accessed from the restoreLookAndFeel() method, which was removed by Rita in version 1.21. I believe this code is now dead, so i suggest removing it.

The second problem is SwingUtilities.invokeLater() in sun.plugin.util.PluginSysUtil - needs to be replaced with EventQueue.

The third one is sun.plugin.AppletViewer which explicitly loads javax.swing.ImageIcon to work around a memory leak in Swing. The memory leak is hopefully fixed on the Swing side - see bug 6482575, fixed in 6u10b05. So hopefully the workaround can now be safely removed, but this needs to be verified.
                                     
2007-12-13



Hardware and Software, Engineered to Work Together