- return ClassLoaderUtils.callWithClassLoader(cls.getClassLoader(), () -> {
- Class<?> moduleInfoClass = Thread.currentThread().getContextClassLoader().loadClass(potentialClassName);
- return (YangModuleInfo) verifyNotNull(moduleInfoClass.getMethod("getInstance").invoke(null));
- });
+ final Class<?> moduleInfoClass;
+ try {
+ moduleInfoClass = cls.getClassLoader().loadClass(potentialClassName);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalStateException("Failed to load " + potentialClassName, e);
+ }
+
+ final Object infoInstance;
+ try {
+ infoInstance = moduleInfoClass.getMethod("getInstance").invoke(null);
+ } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
+ throw new IllegalStateException("Failed to get instance of " + moduleInfoClass, e);
+ }
+
+ checkState(infoInstance instanceof YangModuleInfo, "Unexpected instance %s", infoInstance);
+ return (YangModuleInfo) infoInstance;