OSGi packages won't launch - unable to resolve sun.reflect.generics.reflectiveObjects
After seemingly irrelevant changes in the code of my AEM project, my package cannot solve. When checking the logs, I see the following errors.
22.04.2015 11:00:18.650 *ERROR* [qtp1266495948-35]
org.apache.felix.http.jetty %bundles.pluginTitle:
Cannot start (org.osgi.framework.BundleException:
Unresolved constraint in bundle my-bundle
...
[caused by: Unable to resolve 401.121: missing requirement [401.121]
osgi.wiring.package; (osgi.wiring.package=sun.reflect.generics.reflectiveObjects)]]
The project compiles easily locally and the problem only occurs after installing the package when the container tries to solve it.
I have not added any explicit dependencies in any of my changes. The project object models are the same as before. The name implies that this is a core Java package, so I expect it to be rendered using the System.
I am running JDK 7 which is supported by AEM, so don't expect this to be JVM compatibility related. At least when there are internal AEM details.
source to share
The package sun.reflect.generics.reflectiveObjects
is part of the JDK, but it is not part of the Java API as described in Oracle Documentation for Java 7 Compatibility
Packages
sun.*
are not part of a supported public interface . A Java program that calls packages directly issun.*
not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
This explains why the package is not exported by the System package in Apache Felix, which is the core of AEM. A very smart decision. The code was compiled locally because the package was on my classpath, but it failed at runtime, which is perfectly fine and expected.
My code shouldn't have used this package in the first place. There are two possible ways to add dependencies on these packages.
-
Use a library that for some reason uses these classes and introduces a transitive dependency. This is not what happened.
-
Import one of these classes - a very stupid thing. If anyone is using a class, they need to know what it is.
In my case, I explicitly imported a class from that package without noticing it.
It turns out that the package sun.reflect.generics.reflectiveObjects
contains a class NotImplementedException
whose name matches the commonly used NotImplementedException
from apache.commons.lang3
.
I accidentally imported it when it was autocomplete in my IDE and didn't notice it for a long time. It took me git bisect
to isolate the changes.
After that, I excluded packages sun.*
from autocomplete.
source to share