This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 120624 - ClassCastException from UIUtil.getTreeFolderIcon
Summary: ClassCastException from UIUtil.getTreeFolderIcon
Status: RESOLVED WONTFIX
Alias: None
Product: apisupport
Classification: Unclassified
Component: Project (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: mslama
URL:
Keywords:
Depends on:
Blocks: 70263 72066
  Show dependency tree
 
Reported: 2007-10-31 14:11 UTC by mslama
Modified: 2007-11-02 15:26 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (19.51 KB, text/plain)
2007-10-31 14:15 UTC, mslama
Details
IDE log (39.81 KB, text/plain)
2007-10-31 14:16 UTC, mslama
Details
Patch for GtkLFCustoms.java (1.54 KB, text/plain)
2007-10-31 14:17 UTC, mslama
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mslama 2007-10-31 14:12:02 UTC
When I want to use sun.swing.ImageIconUIResource or com.sun.java.swing.plaf.gtk.GTKIconFactory$SynthExpanderIcon for
explorer folder icon I get ClassCastException from
org.netbeans.modules.apisupport.project.ui.UIUtil.getTreeFolderIcon(UIUtil.java:662). It blocks fix of issue #72066. I
will attach diff for modifying GtkLFCustoms - it is necessary to apply this patch to reproduce this issue. It happens on
GTK L&F.
Comment 1 mslama 2007-10-31 14:13:25 UTC
It happens when I want to expand root node in some nb project eg. core.
Comment 2 mslama 2007-10-31 14:15:14 UTC
Created attachment 52119 [details]
IDE log
Comment 3 mslama 2007-10-31 14:16:02 UTC
Created attachment 52120 [details]
IDE log
Comment 4 mslama 2007-10-31 14:17:29 UTC
Created attachment 52122 [details]
Patch for GtkLFCustoms.java
Comment 5 Jesse Glick 2007-10-31 17:26:09 UTC
You likely know much more about it than I do. If you know what to fix that will work on all platforms, go ahead. For
reference, the code is mkrauskopf's.
Comment 6 mslama 2007-11-01 17:06:23 UTC
Fix is to use Utilities.icon2image on value retrieved from UIManager. Value cannot be directly casted to Image. The same
code is at apisupport/project,java/project,java/j2seproject modules.
Comment 7 mslama 2007-11-01 18:47:05 UTC
I use grep to find out all usages of Utilities.icon2image and then checked if it is really this code pattern. I found 3
occurrences. Fix uses Utilities.icon2image on icon returned from UIManager - second value from UIManager was directly
casted to Image which does not work for all cases. 'Icon' object generaly can just implement javax.swing.Icon interface.

Modified:
/cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UIUtil.java
new revision: 1.40; previous revision: 1.39

/cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java
new revision: 1.25; previous revision: 1.24

/cvs/java/project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java
new revision: 1.29; previous revision: 1.28
Comment 8 mslama 2007-11-02 15:04:26 UTC
I am going to rollback this fix as I found that we put Image instance into these 2 keys "Nb.Explorer.Folder.icon" and
"Nb.Explorer.Folder.openedIcon" for another L&Fs. IMO it is incorrect and should be reviewed. It is not consistent with
UIManager keys as all 'icon' keys are objects implementing Icon interface NOT Image instances. At
http://bits.netbeans.org/dev/javadoc/org-openide-loaders/architecture-summary.html it is documented that:
Nb.Explorer.Folder.icon  - Icon or Image for closed folder.
Nb.Explorer.Folder.openedIcon  - Icon or Image for opened folder.

But current code simply casts returned value to java.awt.Image.

Code should looks like this:
            Object value = UIManager.get(opened ? OPENED_ICON_KEY_UIMANAGER_NB : ICON_KEY_UIMANAGER_NB); // #70263
            if (value instanceof Icon) {
                base = Utilities.icon2Image((Icon) value);
            } else if (value instanceof Image) {
                base = (Image) value;
            }

Jarda suggests we can wrap Image into our own Image subclass which will implement Icon interface. This way we get Object
which can be Image and Icon.
Comment 9 mslama 2007-11-02 15:19:42 UTC
Fix reverted. I will close this issue as WONTFIX. We will discuss and select some solution.

Modified:
/cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UIUtil.java
new revision: 1.41; previous revision: 1.40

/cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java
new revision: 1.26; previous revision: 1.25

/cvs/java/project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java
new revision: 1.30; previous revision: 1.29
Comment 10 mslama 2007-11-02 15:26:49 UTC
Closing