findbugs

Is there a way to ignore a single FindBugs warning?

帅比萌擦擦* 提交于 2019-11-26 17:27:13
问题 With PMD, if you want to ignore a specific warning, you can use // NOPMD to have that line be ignored. Is there something similar for FindBugs? 回答1: The FindBugs initial approach involves XML configuration files aka filters. This is really less convenient than the PMD solution but FindBugs works on bytecode, not on the source code, so comments are obviously not an option. Example: <Match> <Class name="com.mycompany.Foo" /> <Method name="bar" /> <Bug pattern="DLS_DEAD_STORE_OF_CLASS_LITERAL" /

Turning Sonar off for certain code

浪尽此生 提交于 2019-11-26 17:14:05
Is it possible to turn off sonar ( www.sonarsource.org ) measurements for specific blocks of code, which one doesn't want to be measured? An example is the "Preserve Stack Trace" warning which Findbugs outputs. When leaving the server, I might well want to only pass the message back to the client, not including the actual exception which I just caught, if that exception is unknown to the client (because the client doesn't have the JAR in which that exception was contained for example). JB Nizet This is a FAQ . You can put //NOSONAR on the line triggering the warning. I prefer using the

Test for floating point equality. (FE_FLOATING_POINT_EQUALITY)

僤鯓⒐⒋嵵緔 提交于 2019-11-26 16:38:18
I am using a findbugs in an ANT script and I can't figure out how to fix two of my errors. I have read the documentation, but don't understand. Here are my errors and the code that goes with them: Error 1: Test for floating point equality. (FE_FLOATING_POINT_EQUALITY) private boolean equals(final Quantity other) { return this.mAmount == convertedAmount(other); } Error 2: EQ_COMPARETO_USE_OBJECT_EQUALS public final int compareTo(final Object other) { return this.description().compareTo(((Decision) other).description()); } I've read the documentation for the ComparesTo issue that states It is

Findbugs warning: Integer shift by 32 — what does it mean?

淺唱寂寞╮ 提交于 2019-11-26 16:36:56
问题 I was scanning a third party source code using Findbugs (just to be cautious before integrating into it mine), and found the following warning: long a = b << 32 | c Bug: Integer shift by 32 Pattern id: ICAST_BAD_SHIFT_AMOUNT, type: BSHIFT, category: CORRECTNESS The code performs an integer shift by a constant amount outside the range 0..31. The effect of this is to use the lower 5 bits of the integer value to decide how much to shift by. This probably isn't want was expected, and it at least

ResultSet not closed when connection closed?

拥有回忆 提交于 2019-11-26 12:08:32
问题 I\'ve been doing code review (mostly using tools like FindBugs) of one of our pet projects and FindBugs marked following code as erroneous (pseudocode): Connection conn = dataSource.getConnection(); try{ PreparedStatement stmt = conn.prepareStatement(); //initialize the statement stmt.execute(); ResultSet rs = stmt.getResultSet(); //get data }finally{ conn.close(); } The error was that this code might not release resources. I figured out that the ResultSet and Statement were not closed, so I

Turning Sonar off for certain code

吃可爱长大的小学妹 提交于 2019-11-26 04:38:35
问题 Is it possible to turn off sonar (www.sonarsource.org) measurements for specific blocks of code, which one doesn\'t want to be measured? An example is the \"Preserve Stack Trace\" warning which Findbugs outputs. When leaving the server, I might well want to only pass the message back to the client, not including the actual exception which I just caught, if that exception is unknown to the client (because the client doesn\'t have the JAR in which that exception was contained for example). 回答1:

Switch without break

Deadly 提交于 2019-11-26 00:44:34
问题 I have some switch statement as shown below. Notice there is no break. Findbugs is reporting error on the second case statement only. The error is : Switch statement found where one case falls through to the next case. switch(x) { case 0: // code case 1: // code case 2: // code } 回答1: Findbugs is flagging up that falling through from one case to the next is generally not a good idea if there's any code in the first one (although sometimes it can be used to good effect). So when it sees the

解决IntelliJ IDEA 13更新FindBugs 0.9.993时JRE版本过低导致启动失败问题

て烟熏妆下的殇ゞ 提交于 2019-11-25 18:43:36
今晚更新FindBugs 0.9.992(FindBugs 2)至FindBugs 0.9.993(FindBugs 3)后,按要求重启IntelliJ IDEA 13。本想看看更新后多了哪些功能,结果FindBugs悲剧地报错,再次重启,IntelliJ直接禁用了它。 出现这情况,第一时间到IntelliJ的FindBugs主页找找有没解决方案。好吧,评论第一条就说此事。 既然有办法了,那就照着改吧。 可惜,刚开始用Mac,不熟悉这系统。终端上Find这哥们说的IntelliJ.app/Content/Info.plist,一回车,满屏幕的信息,眼都看花了。 试了几次,终于找到修改这路径的办法,在终端上输入 open /Applications/IntelliJ\ IDEA\ 13.app/Contents/Info.plist 回车后,出现Info.plist的内容,查找到JVM的版本,将默认的jre 1.6改成1.7以上,我改成1.8。保存后启动IntelliJ,FindBugs正常工作了。 转载于:https://www.cnblogs.com/michaellfx/p/3903656.html 来源: https://blog.csdn.net/weixin_30556161/article/details/98692519