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 158777

Summary: Do not use getClass().getResource() in forms
Product: guibuilder Reporter: Jesse Glick <jglick>
Component: CodeAssignee: issues@guibuilder <issues>
Status: NEW ---    
Severity: blocker CC: nickdegraeve
Priority: P4    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Suggested patch

Description Jesse Glick 2009-02-18 20:22:40 UTC
The icon editor which picks an icon from a project creates bad code:

  new ImageIcon(getClass().getResource(...))

This is unsafe because a subclass of the form class in a different package will throw an NPE trying to load this icon.
The code should read

  new ImageIcon(ThisClass.class.getResource(...))
Comment 1 Jesse Glick 2009-02-18 20:33:01 UTC
Since it uses an absolute icon path, a subclass would still be able to load the icon even if it were in a different
package, and probably even if in a different class loader (unless package restrictions are in effect). Still poor style
and may trigger warnings from code style checkers looking for getClass().getResource("relative") which is always wrong.
Comment 2 Jesse Glick 2009-02-18 20:36:10 UTC
Created attachment 77125 [details]
Suggested patch
Comment 3 Tomas Pavek 2012-08-17 16:36:30 UTC
*** Bug 122477 has been marked as a duplicate of this bug. ***