JDK-6607310 : InputContext may cause loading of swing classes even for non-Swing applets
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt:i18n
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-09-20
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6u10Fixed 7 b38Fixed
Related Reports
Relates :  
  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.

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.

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 ] ###@###.###