Return-Path: Delivered-To: apmail-felix-dev-archive@www.apache.org Received: (qmail 56391 invoked from network); 23 Feb 2009 16:04:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Feb 2009 16:04:24 -0000 Received: (qmail 73653 invoked by uid 500); 23 Feb 2009 16:04:24 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 73365 invoked by uid 500); 23 Feb 2009 16:04:23 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 73348 invoked by uid 99); 23 Feb 2009 16:04:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 08:04:23 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Feb 2009 16:04:22 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 865E9234C4AB for ; Mon, 23 Feb 2009 08:04:02 -0800 (PST) Message-ID: <651328964.1235405042549.JavaMail.jira@brutus> Date: Mon, 23 Feb 2009 08:04:02 -0800 (PST) From: "Guillaume Nodet (JIRA)" To: dev@felix.apache.org Subject: [jira] Commented: (FELIX-953) Bundle#loadClass sometimes return null instead of throwing a CNFE In-Reply-To: <2023553626.1235163061790.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/FELIX-953?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12675959#action_12675959 ] Guillaume Nodet commented on FELIX-953: --------------------------------------- I might see why IWire sometimes returns null and sometimes throw an exception (though not really confident about that yet), but but afaik, IModule really represents the bundle, so I don't really see why that one would return a null value instead of throwing a CNFE. Would that makes sense to you that IModule#getClassByDelegation() always throw an exception ? Looking deeper in the code, i've just found another possible NPE in ServiceRegistrationImpl#isClassAccessible where the clazz parameter can be null from a call to ServiceRegistrationImpl#isAssignableTo(). That one is harmless because catched, but it could be avoided nevertheless (which is good when debugging when i sometimes but a breakpoint exception on NPE). > Bundle#loadClass sometimes return null instead of throwing a CNFE > ----------------------------------------------------------------- > > Key: FELIX-953 > URL: https://issues.apache.org/jira/browse/FELIX-953 > Project: Felix > Issue Type: Bug > Components: Framework > Reporter: Guillaume Nodet > Priority: Blocker > Attachments: FELIX-953.patch > > > Here is a patch: > {code} > Index: src/main/java/org/apache/felix/framework/Felix.java > =================================================================== > --- src/main/java/org/apache/felix/framework/Felix.java (revision 746347) > +++ src/main/java/org/apache/felix/framework/Felix.java (working copy) > @@ -1338,7 +1338,12 @@ > throw new ClassNotFoundException(name, ex); > } > } > - return bundle.getCurrentModule().getClassByDelegation(name); > + Class clazz = bundle.getCurrentModule().getClassByDelegation(name); > + if (clazz == null) > + { > + throw new ClassNotFoundException(name); > + } > + return clazz; > } > > /** > {code} > I'm wondering if there any reason why ModuleImpl#getClassByDelegation(String) returns null instead of throwing a NPE. > Browsing through the code, it seems there are several places where a null value is checked, then a CNFE thrown. > This would also avoid possible NPE in felix code as in Felix#createBundleActivator. > I think it would be nice to iron the definition of IModule#getClassByDelegation to either remove the thrown CNFE or never returns null, as currently both can happen. > The IWire interface has exactly the same problem. > I will try to come up with a patch which will never return a null value for both interfaces. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.