You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Guo Du <on...@duguo.com> on 2009/11/13 22:52:28 UTC

felix class loader throw NullPointerException instead of ClassNotFoundException when try to load class with empty package name

Hi dev,

I encounter an edge case of felix class loader for empty package name.

THE PROBLEM
org.apache.felix.framework.ModuleImpl$ModuleClassLoader throw
NullPointerException when try to load class with default package name
(empty package name).
Felix framework version 2.0.0 (2.0.2 have the same problem)

BACKGROUND
I installed groovy 1.6.5 official release to felix framework, when
evaluate my script, it throw the NullPointerException because groovy
try to dynamically load java.util.Calendar. During the scan, it will
try to load class "java$util$Calendar". The wired format will be
treated by felix class loader as a class with an empty package name.
Following are the stack trace.
Caused by: java.lang.NullPointerException
	at org.apache.felix.framework.FelixResolverState.getResolvedCandidates(FelixResolverState.java:652)
	at org.apache.felix.framework.Felix$FelixResolver.getResolvedCandidates(Felix.java:3993)
	at org.apache.felix.framework.ModuleImpl.diagnoseClassLoadError(ModuleImpl.java:2144)
	at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:60)
	at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1644)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:300)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:660)

OPTION 1
org.apache.felix.framework.ModuleImpl
line:2136        try
line:2137        {
line:2138            pkgReq = new
Requirement(ICapability.PACKAGE_NAMESPACE, "(package=" + pkgName +
")");
line:2139        }
line:2140        catch (InvalidSyntaxException ex)
line:2141        {
line:2142            // This should never happen.
line:2143        }
line:2144        PackageSource[] exporters =
line:2145            resolver.getResolvedCandidates(pkgReq);

We need handle the exception at line:2142 or do something different
before line 2138.

OPTION 2
The InvalidSyntaxException is coming from
org.osgi.framework.FrameworkUtil @version $Revision: 6499 $
line:1510	if (size == 0) {
line:1511		throw new InvalidSyntaxException("Missing value: "
line:1512			+ filterstring.substring(pos), filterstring);
line:1513	}

Alternatively, we may fix it in FrameworkUtil to handle it properly
for empty package name.

OPTION 3
It works by design of OSGi spec, I need work with groovy community to
make it doesn't scan empty package.

I am not sure the side affect of possible fix, so leave the discussion
to felix community to decide what to do.

Thanks very much to share your thoughts!

-Guo

Re: felix class loader throw NullPointerException instead of ClassNotFoundException when try to load class with empty package name

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 11/14/09 8:35, Guo Du wrote:
> On Fri, Nov 13, 2009 at 10:43 PM, Richard S. Hall<he...@ungoverned.org>  wrote:
>    
>> I noticed this too just recently in GlassFish when there is an attempt to
>> create a dynamic import for something in the default package. Your diagnosis
>> is correct as to where and why the error is happening.
>>
>> Could you open up a JIRA issue for this? I will get it fixed in trunk.
>>      
> Hi Richard,
>
> I found the problem only happens when felix lunched in debug mode. The
> bug recorded at following JIRA:
> ModuleImpl diagnoseClassLoadError throw NullPointerException for empty
> package name in debug mode
> https://issues.apache.org/jira/browse/FELIX-1867
>    

Thanks for reporting it...we will get it fixed.

-> richard

> Thank you very much.
>
> -Guo
>    

Re: felix class loader throw NullPointerException instead of ClassNotFoundException when try to load class with empty package name

Posted by Guo Du <mr...@gmail.com>.
On Fri, Nov 13, 2009 at 10:43 PM, Richard S. Hall <he...@ungoverned.org> wrote:
> I noticed this too just recently in GlassFish when there is an attempt to
> create a dynamic import for something in the default package. Your diagnosis
> is correct as to where and why the error is happening.
>
> Could you open up a JIRA issue for this? I will get it fixed in trunk.

Hi Richard,

I found the problem only happens when felix lunched in debug mode. The
bug recorded at following JIRA:
ModuleImpl diagnoseClassLoadError throw NullPointerException for empty
package name in debug mode
https://issues.apache.org/jira/browse/FELIX-1867

Thank you very much.

-Guo

Re: felix class loader throw NullPointerException instead of ClassNotFoundException when try to load class with empty package name

Posted by "Richard S. Hall" <he...@ungoverned.org>.
I noticed this too just recently in GlassFish when there is an attempt 
to create a dynamic import for something in the default package. Your 
diagnosis is correct as to where and why the error is happening.

Could you open up a JIRA issue for this? I will get it fixed in trunk.

Thanks.

-> richard

On 11/13/09 16:52, Guo Du wrote:
> Hi dev,
>
> I encounter an edge case of felix class loader for empty package name.
>
> THE PROBLEM
> org.apache.felix.framework.ModuleImpl$ModuleClassLoader throw
> NullPointerException when try to load class with default package name
> (empty package name).
> Felix framework version 2.0.0 (2.0.2 have the same problem)
>
> BACKGROUND
> I installed groovy 1.6.5 official release to felix framework, when
> evaluate my script, it throw the NullPointerException because groovy
> try to dynamically load java.util.Calendar. During the scan, it will
> try to load class "java$util$Calendar". The wired format will be
> treated by felix class loader as a class with an empty package name.
> Following are the stack trace.
> Caused by: java.lang.NullPointerException
> 	at org.apache.felix.framework.FelixResolverState.getResolvedCandidates(FelixResolverState.java:652)
> 	at org.apache.felix.framework.Felix$FelixResolver.getResolvedCandidates(Felix.java:3993)
> 	at org.apache.felix.framework.ModuleImpl.diagnoseClassLoadError(ModuleImpl.java:2144)
> 	at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:60)
> 	at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1644)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:300)
> 	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:660)
>
> OPTION 1
> org.apache.felix.framework.ModuleImpl
> line:2136        try
> line:2137        {
> line:2138            pkgReq = new
> Requirement(ICapability.PACKAGE_NAMESPACE, "(package=" + pkgName +
> ")");
> line:2139        }
> line:2140        catch (InvalidSyntaxException ex)
> line:2141        {
> line:2142            // This should never happen.
> line:2143        }
> line:2144        PackageSource[] exporters =
> line:2145            resolver.getResolvedCandidates(pkgReq);
>
> We need handle the exception at line:2142 or do something different
> before line 2138.
>
> OPTION 2
> The InvalidSyntaxException is coming from
> org.osgi.framework.FrameworkUtil @version $Revision: 6499 $
> line:1510	if (size == 0) {
> line:1511		throw new InvalidSyntaxException("Missing value: "
> line:1512			+ filterstring.substring(pos), filterstring);
> line:1513	}
>
> Alternatively, we may fix it in FrameworkUtil to handle it properly
> for empty package name.
>
> OPTION 3
> It works by design of OSGi spec, I need work with groovy community to
> make it doesn't scan empty package.
>
> I am not sure the side affect of possible fix, so leave the discussion
> to felix community to decide what to do.
>
> Thanks very much to share your thoughts!
>
> -Guo
>