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