findbugs

Why do I get a “Possible null pointer dereference” warning?

大城市里の小女人 提交于 2019-12-11 09:19:09
问题 Why do FindBugs raises me the following warning: Possible null pointer dereference . current = myService.getCategoryParent(current); if (current != null) { // The warning appears here I don't understand how testing a variable against null could dereference it. 回答1: I suspect the error/warning is actually on the line above the line you've indicated. // here ------------v current = myService.getCategoryParent(current); if (current != null) { 来源: https://stackoverflow.com/questions/10312399/why

Use PMD to check someObject.methodCall when someObject exists in base class

六月ゝ 毕业季﹏ 提交于 2019-12-10 21:05:43
问题 We have applications that use the Spring framework's NamedParameterJdbcTemplate to execute various JDBC statements. Most of the methods in this class are overloaded. For example, one version of update() accepts a Map, where the keys are bind variable names, values are variable substitutions. Another version accepts a SqlParameterSource, which allows column type information to be supplied as well. I would like to write a rule that flags use of the Map version, because supplying type

Synchronization on boxed primitive

会有一股神秘感。 提交于 2019-12-10 18:29:26
问题 I am new to multithreaded programming. So I need some help to this issue. I get a findbugs bug with synchronization on a boxed primitive: http://findbugs.sourceforge.net/bugDescriptions.html#DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE I tried some solutions on this site but it doesn't work as I expected. Sometimes I get a similar error from findbugs. My code needs a lock on a id which I pass to a constructor, here is some pseudocode: public class MyClass{ public MyClass(long id){ synchronized(id){

FindBugs and static initialization order

99封情书 提交于 2019-12-10 17:49:46
问题 I have the following Java code: public class Something { static { new Something(); } public static final int[] EMPTY_INT_ARRAY = new int[0]; } I'm using FindBugs to look for code errors, but the following error is never raised: SI: Static initializer creates instance before all static final fields assigned (SI_INSTANCE_BEFORE_FINALS_ASSIGNED) The class's static initializer creates an instance of the class before all of the static final fields are assigned. Is this the correct case that should

What bugs apply to the different FindBugs reportLevels?

核能气质少年 提交于 2019-12-10 17:26:02
问题 According to the Ant task, the report level is a low/medium/high setting that would look for bugs of different criticallity levels. However, there isn't anything I could find that explains which of the bugs apply to these different reporting levels. Is there somewhere that provides this, even if it is something I need to look at within the source? 回答1: Unfortunately the association between the bug type and the priority is in the detector code itself. In fact, the same bug type can be reported

alternative to FindBugs DefaultAnnotation for javax.annotation for fields and methods

℡╲_俬逩灬. 提交于 2019-12-10 17:16:09
问题 I currently use @DefaultAnnotation(NonNull.class) package jobs; import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; however the annotation @edu.umd.cs.findbugs.annotations.DefaultAnnotation is deprecated: http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/DefaultAnnotation.html They propose to use javax.annotation.ParametersAreNonnullByDefault However, DefaultAnnotation not only targets parameters, but also fields and

How to configure Gradle findbugs plugin to provide more description for bugs?

空扰寡人 提交于 2019-12-10 15:49:00
问题 Is there a way to add or link to more bug descriptions in the report? I mean good explanations of errors like RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE like in the GUI mode. Some bug titles are not immediately clear. Example for a description: RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE : A value is checked here to see whether it is null, but this value can't be null because it was previously dereferenced and if it were null a null pointer exception would have occurred at the earlier

Findbugs fails with “java.io.IOException: No files to analyze could be opened”

血红的双手。 提交于 2019-12-10 09:59:38
问题 I run an Android Studio v2.1.3 and use ./gradlew build to detect errors in the Android project with the Findbags. Recently an error started to come up: FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':process:customFindbugs'. > java.io.IOException: No files to analyze could be opened There are enough disk space and RAM and beside that I don't see any particular reason for that error to occur. Please help to elaborate on this problem. 回答1: If you use 3.2,

从FindBugs中学Java【三】

删除回忆录丶 提交于 2019-12-10 09:53:46
2. BX_BOXING_IMMEDIATELY_UNBOXED double a = 100d; double d = Double.valueOf(a); Primitive value is boxed and then immediately unboxed. 非必要的装箱并立即拆箱操作. Intellij 也会给这样的提示: 没什么好说的 3. IJU_SETUP_NO_SUPER 好像是个遗留问题,出现在JUnit3的时代,e.g. JUnit3里会这么做 public class TheTest extends TestCase { // test methods ... public static Test suite() { return new TestSetup(new TestSuite(TheTest.class)) { protected void setUp() throws Exception { super.setUp(); // set-up code called only once } protected void tearDown() throws Exception { // tear-down code called only once super.tearDown(); } }; 所以需要这个super.setUp()来初始化

List of FindBugs 2.0 bugs by rank?

只谈情不闲聊 提交于 2019-12-10 03:09:21
问题 I know there is list of bugs, but I would like to have a list with additional information about rank (1 to 20 in version 2.0) or at least about ranking groups (Of concern, Troubling, Scary, Scariest). Maybe I'm missing something, but FindBugs forum does not seem to be active?! 回答1: Perhaps http://code.google.com/p/findbugs/source/browse/trunk/findbugs/etc/bugrank.txt but I don't know if it is exhaustive (FindBugs Bug Descriptions has more entries). 来源: https://stackoverflow.com/questions