编译检查插件框架以执行无零返回
Java是否有任何框架 /编译器插件 /静态分析工具
- 明确标记为无效(通过注释或其他方式),
- 强制执行所有返回值,除非在给定的包装列表中
这本质上意味着强制执行kotlin模型,默认情况下,除非明确标记,否则什么都不是无效的。
请注意,仅查找@notnull注释并仅执行这些工具就不够,不允许null返回值是默认值。或者,该工具可以集中于可能为null的删除值,并强制执行除非标记为null,否则它们可能会要求您进行零检查。
显然,您仍然可以提出有关这种解决方案的问题,因为显然是将它们联系在一起的问题。也很高兴找出是否已经被问到,我自己找不到一个匹配的现有问题。
Is there any framework / compiler plugin / static analysis tool for Java that
- Enforces that all return values are non-null unless they are explicitly marked as Nullable (via annotation or another way)
- in a given list of packages
In essence that would mean enforcing the Kotlin model, where by default nothing can be null, unless it is specifically marked.
Note that a tool that just looks for @Notnull annotations and enforces only those would not be sufficient, not allowing null return values should be the default. Alternatively the tool can focus on dereferencing values that might be null and enforce that they cannot be null unless marked as such and then they may require you to do a null check.
You can obviously still bring questions that go for that kind of solution up as related questions obviously to link them together. Also happy to find out whether this has already been asked, did not find a matching existing question myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
nullness检查器 rel =“ nofollow noreferrer”>检查器框架这样做。
关于您的第一个要求, nullness检查器文档:
关于第二个要求,您可以使用
-aonlydefs
命令行选项。它的文档说:它与完全合格的类名称匹配,因此您可以指定一个软件包名称。
The Nullness Checker of the Checker Framework does this.
Regarding your first requirement, the Nullness Checker documentation says:
Regarding your second requirement, you can use the
-AonlyDefs
command-line option. Its documentation says:It matches fully-qualified class names, so you can specify a package name.
除了Mernst的接受答案外,我还找到了用于错误框架的Nullaway插件。
教程: https://wwwww.baeldung.com/java-nullaway
主页: https://github.com/uber/nullaway
重点,到目前为止,它们似乎都与我需要的东西相匹配。
In addition to the accepted answer from mernst, I have also found the NullAway plugin for the ErrorProne framework.
Tutorial: https://www.baeldung.com/java-nullaway
Main page: https://github.com/uber/NullAway
Will have to try out both at some point, so far they seem both to match what I need.