mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-02 05:17:26 +00:00
[Fix] Core, Framework-API 将 Framework 中 'initial()' 的调用转移到 FrameworkFactory 中, 以解决类初始化问题;
[Change] Framework 移除 'initial()' 的调用, 以修复类初始化过程中的一些隐式问题(如因父类尚未初始化完成, 导致子类成员变量尚未初始化, 出现 NPE 的问题); [Change] FrameworkFactory 将 Framework 的初始化转移到此, 以修复类初始化过程中的一些隐式问题(如上);
This commit is contained in:
@ -65,19 +65,29 @@ final class FrameworkFactory implements PluginFactory {
|
||||
|
||||
// 如果成功获取类, 就需要对其检查, 以确保类符合框架主类的要求.
|
||||
int modifiers = pluginClass.getModifiers();
|
||||
if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)
|
||||
|| (!Framework.class.isAssignableFrom(pluginClass))) {
|
||||
log.error("The framework class '{}' is not valid", pluginClassName);
|
||||
if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) {
|
||||
log.error("The framework class '{}' is not valid: Classes are abstract, or interfaces", pluginClassName);
|
||||
return null;
|
||||
} else if (!Framework.class.isAssignableFrom(pluginClass)) {
|
||||
log.error("The framework class '{}' is not valid: Class is not a subclass of the Framework",
|
||||
pluginClassName);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// <init>(PluginWrapper, DataFolder)
|
||||
Constructor<?> constructor = pluginClass
|
||||
Class<? extends Framework> frameworkClass = pluginClass.asSubclass(Framework.class);
|
||||
Constructor<?> constructor = frameworkClass
|
||||
.getConstructor(PluginWrapper.class, File.class, FrameworkContext.class);
|
||||
return (Framework) constructor.newInstance(pluginWrapper,
|
||||
Framework instance = (Framework) constructor.newInstance(pluginWrapper,
|
||||
new File(dataRootFolder, pluginWrapper.getPluginId()),
|
||||
new DefaultFrameworkContext(eventExecutor, cacheStoreBuilder));
|
||||
try {
|
||||
instance.initial();
|
||||
} catch (Throwable e) {
|
||||
throw new IllegalStateException("An exception occurred while initializing the framework", e);
|
||||
}
|
||||
return instance;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user