Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.nutz.mvc.impl.Loadings中调用ioc.get(ModuleScanner.class, nm)可能会导致NPE错误 #1604

Open
zhaoyangyingmu opened this issue Aug 6, 2022 · 2 comments

Comments

@zhaoyangyingmu
Copy link

Hello,
我发现在org.nutz.mvc.impl.Loadings的第121行处对ioc的直接解析可能会导致NPE错误,如下:

public static Set<Class<?>> scanModules(Ioc ioc, Class<?> mainModule, EntryDeterminer determiner) {
        Modules ann = mainModule.getAnnotation(Modules.class);
            for (String str : ann.by()) {
                if (str.startsWith("ioc:")) {
                    ms = ioc.get(ModuleScanner.class, nm);// 可能发生NPE错误。
                }
}

传递的null值在NutLoading的第87行,返回值可能为空。

ioc = createIoc(config, mainModule);

希望这个建议对你们有帮助!!

@wendal
Copy link
Member

wendal commented Aug 8, 2022

但总得抛出异常吧

@zhaoyangyingmu
Copy link
Author

zhaoyangyingmu commented Aug 8, 2022

方案一:检查ioc为null时,输出warning信息,并退出。
方案二:检查ioc为null时,输出warning信息,不进行解引用,继续跑程序。
方案三:检查ioc为null时,不输出warning信息,不进行解引用,继续跑程序。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants