United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6607310 InputContext may cause loading of swing classes even for non-Swing applets
JDK-6607310 : InputContext may cause loading of swing classes even for non-Swing applets

Details
Type:
Enhancement
Submit Date:
2007-09-20
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
generic
Sub-Component:
java.awt:i18n
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

Description
Running 
  appletviewer -J-verbose:class demo\applets\ArcTest\example1.html 
shows that JComponent/JPanel are loaded.

This creates additional unneeded hard dependency between different subsystsems.
Also JComponent class is fairly large (over 40k).

We should avoid loading classes unless they are needed.

                                    

Comments
EVALUATION

Loading happens because of the
                if (source instanceof CompositionArea) {
in the void focusGained().

instanceof causes class resolution (see 6592631) and CompositionArea extends JPanel.

Clearly source can not be CompositionArea if this class was not loaded yet.

Avoiding of loading is possible in following way:
  1) Add boolean variable isCompositionAreaResolved to the InputContext (or any other class)
  2) Add static block to CompositionArea that sets InputContext.isCompositionAreaResolved to true
  3) rewrite condition as
     if (isCompositionAreaResolved && source instanceof CompositionArea)

Alternatively it is possible to use AWT approach (see Component.isInstanceOf()).
 



*** (#1 of 1): [ UNSAVED ] ###@###.###
                                     
2007-09-20
EVALUATION

I don't think use of operators could be a defect.

Since CompositionArea is not subclassed, I changed the if-expression to:

if ("sun.awt.im.CompositionArea".equals(source.getClass().getName())) {

After the change, the number of loaded Swing classes with ArcTest was reduced to 2 from 5 on Windows. However, it was 263 from 264 on Linux.
                                     
2007-09-21



Hardware and Software, Engineered to Work Together