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 - Do not use getClass().getResource() in forms
Summary: Do not use getClass().getResource() in forms
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P4 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
: 122477 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-18 20:22 UTC by Jesse Glick
Modified: 2012-08-17 16:36 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Suggested patch (890 bytes, patch)
2009-02-18 20:36 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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. ***