java 我可以告诉 findbugs 忽略我无法添加的类吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3373837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I tell findbugs to ignore classes I am unable to add?
提问by Nicolas
Findbugs reports this:
Findbugs 报告了这一点:
findbugs:
[findbugs] Executing findbugs from ant task
[findbugs] Running FindBugs...
[findbugs] The following classes needed for analysis were missing:
[findbugs] com.company.OptionalClass
[findbugs] Warnings generated: 11
[findbugs] Missing classes: 2
[findbugs] Calculating exit code...
[findbugs] Setting 'missing class' flag (2)
[findbugs] Setting 'bugs found' flag (1)
[findbugs] Exit code set to: 3
[findbugs] Java Result: 3
[findbugs] Classes needed for analysis were missing
[findbugs] Output saved to findbugs.xml
BUILD SUCCESSFUL
This OptionalClass is referenced from a third-party jar for which I do not have the source code, and for which I do not want a findbugs analysis. It refers to a class I do not have in my classpath, or anywhere else. This class is probably used in certain cases, when our third-party jar is configured in a certain way.
这个 OptionalClass 是从第三方 jar 引用的,我没有源代码,并且我不想对其进行 findbugs 分析。它指的是我的类路径或其他任何地方都没有的类。当我们的第三方 jar 以某种方式配置时,这个类可能会在某些情况下使用。
Is there a way to tell findbugs to ignore this class?
有没有办法告诉 findbugs 忽略这个类?
Note that it completes the analysis and produces a findbugs.xmlreport, so this is a minor issue.
请注意,它会完成分析并生成findbugs.xml报告,因此这是一个小问题。
采纳答案by Grundlefleck
This message appears because somewhere in your binary classes you are referencing that class. It does not necessarily mean that FindBugs was trying to analyse com.company.OptionalClassto report on it; rather it is more likely FindBugs was analysing it to get more information about the class which references it.
出现此消息是因为您在二进制类中的某处引用了该类。这并不一定意味着 FindBugs 试图分析com.company.OptionalClass以报告它;相反,FindBugs 更有可能分析它以获取有关引用它的类的更多信息。
Consider some of your source code, which you do want analysed:
考虑一些您确实想要分析的源代码:
package my.actual.codebase;
import com.some.third.party.stuff.OptionalClass;
class ReferencesOptionalClass extends OptionalClass {}
This kind of example is common with test classes, which reference e.g. org.junit.@Testbut the JUnit jar is not included in what you want to analyse.
这种示例在测试类中很常见,它引用了例如org.junit.@Test但 JUnit jar 不包含在您要分析的内容中。
In the above example you do want results for ReferenceOptionalClass, but in order to get them, some parts of FindBugs need to look at OptionalClass. If it can't do that, because it's not there, it reports that the class is missing[1]. When FindBugs can't find that class, it generally just aborts the specific kind of analysis it was trying to do, and carries on with the rest of the analysis without problem.
在上面的示例中,您确实需要 的结果ReferenceOptionalClass,但是为了获得它们,FindBugs 的某些部分需要查看OptionalClass。如果它不能这样做,因为它不存在,它会报告该类丢失[1]。当 FindBugs 找不到那个类时,它通常只是中止它试图进行的特定类型的分析,并继续进行其余的分析而不会出现问题。
The simple answer is if you are happy with the level of analysis FindBugs is giving you, then just ignore the error.
简单的答案是,如果您对 FindBugs 提供的分析级别感到满意,那么只需忽略错误即可。
[1] Note that it's likely that this could even be a transitive reference i.e. your code includes class A, which references B in an auxiliary JAR, which then references OptionalClass.
[1] 请注意,这甚至可能是一个传递引用,即您的代码包含类 A,该类引用辅助 JAR 中的 B,然后引用 OptionalClass。
回答by u351545
To ignore the third-party classes, specify an option -auxclasspath classpathwhen using command-line or provide an nested element <auxClasspath refid="classpath">when using anttask, where your third-party jar is in the classpath.
要忽略第三方类,请-auxclasspath classpath在使用命令行时指定一个选项或<auxClasspath refid="classpath">在使用ant任务时提供嵌套元素,其中第三方 jar 位于 classpath.
回答by MeBigFatGuy
No, But you do not need source or to generate findbugs reports for this code if you add the jar to the 'auxillary jars' section of the findbugs project file.
不,但是如果您将 jar 添加到 findbugs 项目文件的“辅助 jars”部分,则不需要源代码或为此代码生成 findbugs 报告。

