felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guo Du <onl...@duguo.com>
Subject felix class loader throw NullPointerException instead of ClassNotFoundException when try to load class with empty package name
Date Fri, 13 Nov 2009 21:52:28 GMT
Hi dev,

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

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)

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)

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.

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.

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!


View raw message