frameworkutil: Fix NPE when class is from bootstrap class loader
@@ -231,11 +231,13 @@ public class FrameworkUtil {
public static Bundle getBundle(Class< ? > classFromBundle) {
// We use doPriv since the caller may not have permission
// to call getClassLoader.
- ClassLoader cl = AccessController.doPrivileged(
+ Optional<ClassLoader> cl = Optional
+ .ofNullable(AccessController.doPrivileged(
(PrivilegedAction<ClassLoader>) () -> classFromBundle
- .getClassLoader());
+ .getClassLoader()));
- return getBundle(cl).orElseGet(() -> helpers.stream()
+ return cl.flatMap(FrameworkUtil::getBundle)
+ .orElseGet(() -> helpers.stream()
.map(helper -> helper.getBundle(classFromBundle))
.filter(Optional::isPresent)
.map(Optional::get)
