OSGi bundles won't start - Unable to resolve sun.reflect.generics.reflectiveObjects

此生再无相见时 提交于 2019-12-01 22:47:42

The package sun.reflect.generics.reflectiveObjects is part of the JDK but it's not part of the Java API, as explained in Oracle's documentation for Java 7 compatibility

The sun.* packages are not part of the supported, public interface. A Java program that directly calls into sun.* packages is 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 bundle in Apache Felix, underlying AEM. A very reasonable decision indeed. The code compiled locally because the package was in my classpath but it failed at runtime, which is all fine and to be expected.

My code should not have been using this package in the first place. There are two possible ways of introducing a dependency on these packages.

  1. Use a library that uses these classes for some reason and introduce a transitive dependency. This isn't what happened.

  2. Import one of these classes - a very silly thing to do. If someone uses a class, they should know what it is.

In my case, I explicitly imported a class from this package without noticing it.

It turns out that the sun.reflect.generics.reflectiveObjects package contains a NotImplementedException class, the name of which coincides with the often-used NotImplementedException from apache.commons.lang3.

I accidentally imported it when it was auto-completed in my IDE and failed to notice this for a long time. It took me a git bisect to isolate the change.

After this happened, I excluded the sun.* packages from autocomplete.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!