findbugs

What's the advantage of making an inner class as static with Java?

给你一囗甜甜゛ 提交于 2019-11-27 12:10:46
问题 I have an inner class in my Java class. When I run find bugs, it recommends(warns) to make it as static. What's the point of this warning? What's the advantage of making a inner class as static? 回答1: If the nested class does not access any of the variables of the enclosing class, it can be made static. The advantage of this is that you do not need an enclosing instance of the outer class to use the nested class. 回答2: An inner class, by default, has an implicit reference to an object of the

CreateProcess error=206, The filename or extension is too long

浪尽此生 提交于 2019-11-27 09:16:58
I'm trying to call Findbugs via Ant , but receiving this error: Cannot run program "C:\Program Files (x86)\Java\jre6\bin\javaw.exe" (in directory "H:\Users\MyName\workspace\MyProject"): CreateProcess error=206, The filename or extension is too long How can I fix this? o.O I had the same problem. I used <fileset dir="${basedir}/build"> <include name="**/*.class"/> </fileset> inside findbugs target and it seems that there is too much .class files to be passed to findbug (?via command line?) because when I used <fileset dir="${basedir}/build/com/domain/package"> <include name="**/*.class"/> <

When to Garbage Collect

帅比萌擦擦* 提交于 2019-11-27 06:55:15
问题 I have a piece of code that load a very big image in memory. So it seemed like a reasonable thing to call System.gc(); before loading the image. From what I can tell it works with no issues. Yesterday i decided to use a pretty useful piece of software called FindBugs that scans your code and reports back issues that might cause bugs or generally not advised strategies. The problem is that this piece of code i mentioned gets reported. The description is this: ... forces garbage collection;

ResultSet not closed when connection closed?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 06:43:49
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 closed them in finally: finally{ try{ rs.close() }catch(SqlException se){ //log it } try{ stmt.close();

How to suppress FindBugs warnings for fields or local variables

你。 提交于 2019-11-27 06:34:46
问题 I would like to suppress FindBugs warnings for specific fields or local variables. FindBugs documents that the Target can be Type, Field, Method, Parameter, Constructor, Package for its edu.umd.cs.findbugs.annotations.SuppressWarning annotation [1]. But it does not work for me to annotate the field, only when I annotate the method the warning gets suppressed. Annotating a whole method seems to broad to me. Is there any way to suppress warnings on specific fields? There is another related

Set findbugs NotNull as default for all classes under a package

旧巷老猫 提交于 2019-11-27 03:22:49
问题 I have the simple code below for testing the FindBugs @NonNull annotation with Maven. I execute mvn clean install And it correctly fails to build because print(null) violates the non-null condition. You can set NonNull as default for all method parameters inside a class using the class annotation @DefaultAnnotation(NonNull.class) How can I set NonNull as default for all method parameters inside all classes under a given package (and sub-packages)? src/main/java/test/Hello.java package test;

Easy way find uninitialized member variables

谁都会走 提交于 2019-11-27 03:19:51
I am looking for an easy way to find uninitialized class member variables. Finding them in either runtime or compile time is OK. Currently I have a breakpoint in the class constructor and examine the member variables one by one. If you use GCC you can use the -Weffc++ flag, which generates a warnings when a variable isn't initialized in the member initialisation list. This: class Foo { int v; Foo() {} }; Leads to: $ g++ -c -Weffc++ foo.cpp -o foo.o foo.cpp: In constructor ‘Foo::Foo()’: foo.cpp:4: warning: ‘Foo::v’ should be initialized in the member initialization list One downside is that

Is there a way to ignore a single FindBugs warning?

无人久伴 提交于 2019-11-27 00:00:37
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? Pascal Thivent 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" /> </Match> However, to solve this issue, FindBugs later introduced another solution based on

How to generate a html report for findbugs with Maven 3.x

隐身守侯 提交于 2019-11-26 20:17:47
问题 Has anybody managed to configure the findbugs Maven 3.x plugin to produce both an xml and html report? (I want the xml one for Jenkins and the html one for checking prior to a commit) I've seen a lot of documentation on the web on setting this up, but most of it appears to be for Maven 2.x, which I know is configured differently (annoyingly the 2.x configuration is silently ignored by 3.x). I'm new to Maven, so I'm not sure if I'm doing something wrong or I'm following old instructions. My

CreateProcess error=206, The filename or extension is too long

心不动则不痛 提交于 2019-11-26 17:49:06
问题 I'm trying to call Findbugs via Ant , but receiving this error: Cannot run program "C:\Program Files (x86)\Java\jre6\bin\javaw.exe" (in directory "H:\Users\MyName\workspace\MyProject"): CreateProcess error=206, The filename or extension is too long How can I fix this? o.O 回答1: I had the same problem. I used <fileset dir="${basedir}/build"> <include name="**/*.class"/> </fileset> inside findbugs target and it seems that there is too much .class files to be passed to findbug (?via command line?