Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
framework-6.0.1
-
None
Description
A felix initiation error can occur if one adds extra "org.osgi.framework.system.package.extras".
The error produced is caused by a empty package name.
The problem occurs in the class ExtensionManager in the update(Map configMap) method.
It contains the following line:
syspkgs = ((pkgextra == null) || (pkgextra.trim().length() == 0))
? syspkgs : syspkgs + (pkgextra.trim().startsWith(",") ? pkgextra : "," + pkgextra);
When syspkgs has the value "" (the empty string) the result is ",pkgextra". Syspkgs then gets stored in m_headerMap. When that header gets parsed later that comma at the beginning of the string gets interpreted as a blank package name and the class ManifestParser method normalizeExportClauses Method throws an exception:
else if (pkgName.length() == 0)
{
throw new BundleException(
"Exported package names cannot be zero length.");
}
The result is that the remaining extra packages are not exported. Other bundles that need these extra packages of course will not be resolved as a result of this exception, and its easy to miss the fact that the exception was thrown during initialization .
There are two easy solutions to the problem:
1.) in the ExtensionManager update manager make the following change (add one line of code):
syspkgs = ((pkgextra == null) || (pkgextra.trim().length() == 0))
? syspkgs : syspkgs + (pkgextra.trim().startsWith(",") ? pkgextra : "," + pkgextra);
if (syspkgs.startsWith(",")) syspkgs = syspkgs.substring(1);
2.) log an error instead of throwing an exception in the ManifestParser normalizeExportClauses method and just ignore the blank package name, since it doesn't really cause a problem.
I've test solution 1 and it solves the problem, but solution 2 is probably a more robust and forgiving solution.
Note: this problem doesn't occur if syspkgs is not the empty string. So the problem only occurs under certain configurations.