JDK-4711996 : IllegalArgumentException when updating color chooser ui
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2002-07-09
  • Updated: 2003-08-15
  • Resolved: 2003-08-15
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.
Other
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Description

Name: rmT116609			Date: 07/09/2002


FULL PRODUCT VERSION :
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]

DESCRIPTION OF THE PROBLEM :
When calling the method updateUI() of instances of the class javax.swing.JColorChooser an IllegalArgumentException gets thrown if one or more of the defaults chooser panels were removed before.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Execute the attached source code


EXPECTED VERSUS ACTUAL BEHAVIOR :
The expected behaviour is that the BasicColorChooserUI first checks if a chooser panel is available before removing it. Since this does not happen, the actual result is that the exception gets thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: chooser panel not in this chooser
        at javax.swing.JColorChooser.removeChooserPanel(JColorChooser.java:409)
        at javax.swing.plaf.basic.BasicColorChooserUI.uninstallDefaultChoosers
(BasicColorChooserUI.java:60)
        at javax.swing.plaf.basic.BasicColorChooserUI.uninstallUI
(BasicColorChooserUI.java:88)
        at javax.swing.JComponent.setUI(JComponent.java:440)
        at javax.swing.JColorChooser.setUI(JColorChooser.java:209)
        at javax.swing.JColorChooser.updateUI(JColorChooser.java:220)
        at com.incors.bugreports.ColorChooserBug.main(ColorChooserBug.java:14)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.colorchooser.*;

public class ColorChooserBug {
  
  public static void main(String[] args) {
    try {
      JColorChooser colorChooser = new JColorChooser();
      AbstractColorChooserPanel[] colorChooserPanels = colorChooser.getChooserPanels();
      colorChooser.removeChooserPanel(colorChooserPanels[0]);
      colorChooser.updateUI();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  
}
---------- END SOURCE ----------

CUSTOMER WORKAROUND :
There are two possible workarounds:

1. Make a subclass of BasicColorChooserUI and check inside the method uninstallDefaultChoosers() if a chooser panel exists before removing it.

2. Make a subclass of JColorChooser and catch the exception silently inside the method removeChooserPanel()
(Review ID: 159004) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b16
24-08-2004

SUGGESTED FIX Name: keR10081 Date: 08/01/2003 *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/javax/swing/plaf/basic/BasicColorChooserUI.java- Fri May 16 15:07:59 2003 --- BasicColorChooserUI.java Fri May 16 14:38:48 2003 *************** *** 57,64 **** } protected void uninstallDefaultChoosers() { ! for( int i = 0 ; i < defaultChoosers.length; i++) { ! chooser.removeChooserPanel( defaultChoosers[i] ); } } --- 57,65 ---- } protected void uninstallDefaultChoosers() { ! AbstractColorChooserPanel[] choosers = chooser.getChooserPanels(); ! for( int i = 0 ; i < choosers.length; i++) { ! chooser.removeChooserPanel( choosers[i] ); } } ======================================================================
24-08-2004

EVALUATION Will fix for mantis. ###@###.### 2002-10-01 Name: keR10081 Date: 08/01/2003 See suggested fix for details. ###@###.### ======================================================================
01-10-2002