Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6280057
Votes 0
Synopsis I have audited SystemTray and TrayIcon code
Category java:classes_awt
Reported Against
Release Fixed 7(b36)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6759726
Submit Date 03-JUN-2005
Description
FULL PRODUCT VERSION :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b38)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b38, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
 customer  Windows XP [version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
I have audited the code of class java.awt.TrayIcon and java.awt.SystemTray.

I have the following remarks :
- on TrayIcon.java :
  - TrayIcon(Image),  the test to null is not necessary because setImage()
     test null too.
 - getMouseListeners/getMouseMotionListeners and getActionListeners
    uses an internal method getListeners that select select
    the corresponding AWTEventMulticaster field and delegate to
    AWTEventMulticaster.getListeners. I think this method is useless,
    and all get*Listeners could directly calls AWTEventMulticaster.getListeners
    with theire corresponding fields.

    Ex:
    public synchronized MouseListener[] getMouseListeners() {
        return AWTEventMulticaster.getListeners(
           mouseListener,MouseListener.class));
    }

    Futhermore, the cast to the listener array is not necessary because
    the same is inserted by the compiler during the erasure pass
    of the generics.

  - displayMessage(), at the end of the method, replace
    messageType.toString() by messageType.name() because
    toString() is a method for debugging purpose.
    
-  on SystemTray.java :
 - on imports, java.util.Map and java.util.HashMap seems not used
    anymore, perhaps because maps was replaced by AppContext.

  - isSupported() have a lot of Toolkit.getDefaultToolkit(), i think a code
    like this is more readable :

    public static boolean isSupported() {
        Toolkit toolkit=Toolkit.getDefaultToolkit();
        if (toolkit instanceof SunToolkit) {
            return ((SunToolkit)toolkit).isTraySupported();
        } else if (toolkit instanceof HeadlessToolkit) {
            return ((HeadlessToolkit)toolkit).isTraySupported();
        }
        return false;
    }
  
  - TrayIcon[] getTrayIcons()
    defined a constant to avoid creation of empty array.
    
    public TrayIcon[] getTrayIcons() {
        Vector<TrayIcon> icons = (Vector<TrayIcon>)AppContext.getAppContext().get(systemTray);
        if (icons != null) {
            return (TrayIcon[])icons.toArray(new TrayIcon[icons.size()]);
        }
        return EMPTY_TRAY_ARRAY;
    }
    private static final TrayIcon[] EMPTY_TRAY_ARRAY=new TrayIcon[0];

  that'all folks :)


REPRODUCIBILITY :
This bug can be reproduced always.
  xxxxx@xxxxx   2005-06-03 09:29:05 GMT
Work Around
N/A
Evaluation
Good feedback in common =)
  xxxxx@xxxxx   2005-06-29 15:17:34 GMT
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang