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 57815

Summary: NBBundle.getMessage(...) throws NPE rather than MRE
Product: platform Reporter: santhosh <santhosh>
Component: -- Other --Assignee: Jesse Glick <jglick>
Status: RESOLVED FIXED    
Severity: blocker CC: jchalupa
Priority: P4    
Version: 4.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description santhosh 2005-04-13 08:51:49 UTC
NBBundle.getMessage(...) throws NPE rather than MissingResourceException
for the following statement:
   NBBundle.getMessage(JLabel.class, "SOME_KEY");

this problem is there is no guaranty that Class.getClassLoader() always returns
non null value (see javadoc)

so NPE is thrown at line: 
      loader.getResource(...)

it should have obtained classloader like this:
   ClassLoader loader = clazz.getClassLoader();
   if(loader==null)
       loader = ClassLoader.getSystemClassLoader();
Comment 1 santhosh 2005-04-13 08:52:54 UTC
i am using netbeans 4.1 beta with j2sdk 1.4.0_02 on windows 2000
Comment 2 Jan Chalupa 2005-11-09 18:05:11 UTC
Jesse, any comments?
Comment 3 Jesse Glick 2005-11-10 00:51:32 UTC
True. Not clear why you would be doing that to begin with, though. NbBundle is
intended for usage with module classes, which always have a class loader.

BTW: ClassLoader.getSystemClassLoader if non-null is different from the null
primordial loader, or may itself be null, so the suggested patch is not quite
correct, though it may have the intended effect in common cases. Better would be
to use CL.getSystemResource if loader == null; CL.getBootstrapResource would be
perfect but it is private.
Comment 4 santhosh 2005-11-10 01:06:07 UTC
I am using netbeans way of internationationalizing in non-netbeans libraries

I have created a class I18N.java which is same as NBBundle.jar.
say xyz.jar one such jar;
i have added xyz to netbeans using -classpath:a

now from netbeans module, if i do:

NBBundle(<someclassinxyz.jar>, "key") , it throws NPE

as xyz.jar is not loaded by netbeans classloader. here xyz.jar is loaded by java
system/bootstrap classloader.

this is the sideeffect of following netbeans i18n conventions in non-netbeans
modules which were loaded by systemclassloader when used in netbeans.
Comment 5 Jesse Glick 2005-11-10 04:47:01 UTC
Odd; ClassLoader for a JAR added via -classpath:a should not be null, at least
not in the Sun JRE: null means the bootstrap class loader, i.e. rt.jar and its
associates only.
Comment 6 Jesse Glick 2006-06-06 16:04:03 UTC
Only reproducible for JRE classes, not for -classpath classes. Anyway, fixed.

Checking in src/org/openide/util/NbBundle.java;
/shared/data/ccvs/repository/openide/util/src/org/openide/util/NbBundle.java,v 
<--  NbBundle.java
new revision: 1.15; previous revision: 1.14
done
Checking in test/unit/src/org/openide/util/NbBundleTest.java;
/shared/data/ccvs/repository/openide/util/test/unit/src/org/openide/util/NbBundleTest.java,v
 <--  NbBundleTest.java
new revision: 1.4; previous revision: 1.3
done