Questions tagged [findbugs]

A program which uses static analysis to look for bugs in Java code.

FindBugs is an open source program created by Bill Pugh and David Hovemeyer which looks for bugs in Java code. It uses static analysis to identify hundreds of different potential types of errors in Java programs. FindBugs operates on Java bytecode, rather than source code. The software is distributed as a stand-alone GUI application. There are also plug-ins available for Eclipse, Netbeans, IntelliJ IDEA, and Hudson.

Related Links:

1001 questions
266
votes
7 answers

Turning Sonar off for certain code

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…
Ant Kutschera
  • 6,257
  • 4
  • 29
  • 40
215
votes
7 answers

Is there a way to ignore a single FindBugs warning?

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?
Ben S
  • 68,394
  • 30
  • 171
  • 212
126
votes
8 answers

Is SonarQube Replacement for Checkstyle, PMD, FindBugs?

We are working on a web project from scratch and are looking at the following static code analysis tools. Conventions (Checkstyle) Bad practices (PMD) Potential bugs (FindBugs) The project is built on Maven. Instead of using multiple tools for…
Johnny
  • 1,317
  • 2
  • 10
  • 6
113
votes
3 answers

What are the differences between PMD and FindBugs?

There was a question comparing PMD and CheckStyle. However, I can't find a nice breakdown on the differences/similarities between PMD and FindBugs. I believe a key difference is that PMD works on source code, while FindBugs works on compiled…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
94
votes
17 answers

Checkstyle vs. PMD

We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so Checkstyle and PMD integration come for free. However it looks like there is a large overlap in functionality between these two tools, in…
John Stauffer
  • 16,150
  • 10
  • 40
  • 35
78
votes
9 answers

FindBugs IDEA - ClassNotFoundException com.google.wireless.android.sdk.stats.IntellijIndexingStats

FindBugs IDEA v1.0.1 Android Studio 3.4 I get this error when running FindBugs. I don't use com.google.wireless.android.sdk anywhere in the app. Error:Internal error: (java.lang.ClassNotFoundException)…
tim4dev
  • 2,846
  • 2
  • 24
  • 30
76
votes
1 answer

Found reliance on default encoding

I am getting below bug from FindBugs, Found reliance on default encoding in MyClass.print(String): String.getBytes() Method protected void print (String str) { { private OutputStream outStream =…
Srinivasan
  • 11,718
  • 30
  • 64
  • 92
64
votes
8 answers

How to handle a Findbugs "Non-transient non-serializable instance field in serializable class"?

Consider the class below. If I run Findbugs against it it will give me an error ("Non-transient non-serializable instance field in serializable class") on line 5 but not on line 7. 1 public class TestClass implements Serializable { 2 3 private…
Koohoolinn
  • 1,427
  • 6
  • 20
  • 29
61
votes
8 answers

Incorrect lazy initialization

Findbug told me that I use incorrect lazy initialization. public static Object getInstance() { if (instance != null) { return instance; } instance = new Object(); return instance; } I don't see anything wrong here. Is it…
michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
59
votes
3 answers

javax.annotation: @Nullable vs @CheckForNull

What is the difference between the two? Both seem to mean that the value may be null and should be dealt with accordingly i.e. checked for null. Update: The two annotations above are part of…
vitaly
  • 2,755
  • 4
  • 23
  • 35
50
votes
1 answer

How to generate HTML output using Gradle FindBugs Plugin

Using the Gradle FindBugs Plugin, how can I generate the output in HTML format?? The FindBugsExtension do have some config to set. findbugs { toolVersion = "2.0.1" sourceSets = [sourceSets.main] ignoreFailures = true reportsDir =…
Lai
  • 1,320
  • 2
  • 13
  • 24
49
votes
8 answers

ResultSet not closed when connection closed?

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 =…
jb.
  • 23,300
  • 18
  • 98
  • 136
47
votes
2 answers

@GuardedBy annotation with java.util.concurrent.locks.ReadWriteLock

What is a proper/preferred way to annotate fields that are protected with a ReadWriteLock so that tools like FindBugs can leverage the annotation? Should the name of the ReadWriteLock simply be written in the @GuardedBy annotation. Is there ever a…
Greg Mattes
  • 33,090
  • 15
  • 73
  • 105
43
votes
2 answers

Findbugs issue with "Boxing/unboxing to parse a primitive" with Integer.valueOf(String)

I have this piece of code: public void someMethod(String id) { someOtherMethod(Integer.valueOf(id)); } public void someOtherMethod(int id) { // do something with id } And on that second line, Findbugs is throwing this…
mac
  • 2,672
  • 4
  • 31
  • 43
41
votes
7 answers

Switch without break

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: …
fastcodejava
  • 39,895
  • 28
  • 133
  • 186
1
2 3
66 67