findbugs

What's the best way to fix this 'write to static field from instance method' findbugs warning?

拈花ヽ惹草 提交于 2019-11-30 11:19:32
I have a class that looks similar to this, and findbugz is complaining about the 'write to the static field from the instance method' ( initialize() , and killStaticfield() ). I can't set the static field in the ctor. What is the best fix for this issue? Would putting staticField in an AtomicReference suffice? public class Something { private static SomeClass staticField = null; private AnotherClass aClass; public Something() { } public void initialize() { //must be ctor'd in initialize aClass = new AnotherClass(); staticField = new SomeClass( aClass ); } public void killStaticField() {

Eclipse+FindBugs - exclude filter files doesn't work

让人想犯罪 __ 提交于 2019-11-30 09:45:02
I'm using Windows and Eclipse 3.7 Classic with ADT plugin for Android development. I've just installed FindBugs and it have found a bug in auto-generated R.java class. I want to exclude this class from FindBugs checks. I've found that I can define exclude filters for FindBugs in xml file, so I've created a file D:\Projects\eclipse\FindBugsExculde.xml with text <FindBugsFilter> <Match> <Class name="com.android.demo.notepad3.R$attr" /> </Match> </FindBugsFilter> I've added this file to Eclipse -> Window -> Preferences -> Java -> FindBugs -> Filter files -> "Add..." button near the "Exclude

Writing a detector to search for uses of “System.out.println” using Findbugs

北慕城南 提交于 2019-11-30 05:44:53
问题 I am trying to write a bug detector to find instances of the method call "System.out.println" using Findbugs. I understand that "System.out.println" in bytecode is compiled to a call to GETSTATIC, which pushes "System.out" onto the stack. A call to INVOKEVIRTUAL pops "System.out" off the stack and calls the method. I have prepared some code (found below) which finds the correct GETSTATIC and INVOKEVIRTUAL calls, but have been unable to link the two together. I suspect I may need to use

@Nullable/@NotNull with IntelliJ IDEA, Maven & JSR 305

自作多情 提交于 2019-11-30 04:57:41
I really like the code inspection functionalities which are now able with either JSR 305 or Jetbrains' proprietary annotations for IntelliJ. Unfortunately both implementations (JSR 305 and Jetbrains') do not mix well: IntelliJ obviously only understands its own proprietary set of annotations and integrates them quite well. Using Findbugs in my Maven Build, it only supports JSR-305 annotations. The only possible workaround might be to go for JSR-305 and use the Findbugs plugin in IntelliJ. Has anybody a better idea? (please don't say change your IDE ;) ). Thanks Thomas This has been made

Clean up unused Android permissions

喜你入骨 提交于 2019-11-30 01:15:43
If I wanted to research how and where permissions [requested in the Mainfest.xml] were used in an Android app for the purposes of removing them is there an easy way of doing this? Does lint or findbugs offer some sort of support for tracking permissions used/abused in a project? I came from the future to save your lives. Here (in the future), LINT does check for missing permissions as you can see on LINT checks . So, go to your AndroidManifest.xml and remove all tags <uses-permission> using Android permissions (meaning, don't delete permissions that belong to your app, such as UA_DATA and C2D

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

笑着哭i 提交于 2019-11-29 22:04:38
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 static final long serialVersionUID = 1905162041950251407L; 4 5 private Set<Integer> mySet; // Findbugs error 6 7 private HashSet<Integer> myOtherSet; 8 9 } That's correct because java.util.Set never implements Serializable in its hierarchy and java.util.HashSet does. However it is best practice to code against interfaces instead of concrete

What are the differences between PMD and FindBugs?

旧城冷巷雨未停 提交于 2019-11-29 18:54:26
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 bytecode files. But in terms of capabilities, should it be an either/or choice or do they complement each other? I'm using both. I think they complement each other. As you said, PMD works on source code and therefore finds problems like: violation of naming conventions, lack of curly braces, misplaced null check, long parameter list, unnecessary

Maven Findbugs plugin - How to run findbug on the test classes

最后都变了- 提交于 2019-11-29 18:50:14
问题 Maven version: 3.3.3. Findbugs plugin version: 3.0.1 I'm using the findbugs-maven-plugin and I need to run findbugs plugin on src and test classes. Currently, it is only applied to the source classes Target |_ classes |_ test-classes |_ findbugs (only have results regarding classes folder) I need to do the same for the PMD plugin. Same hint maybe? Related issues: FindBugs filter file for ignoring JUnit tests How to run findbug on the test code Findbugs maven configuration: <profile> <id

Eclipse+FindBugs - exclude filter files doesn't work

冷暖自知 提交于 2019-11-29 14:14:26
问题 I'm using Windows and Eclipse 3.7 Classic with ADT plugin for Android development. I've just installed FindBugs and it have found a bug in auto-generated R.java class. I want to exclude this class from FindBugs checks. I've found that I can define exclude filters for FindBugs in xml file, so I've created a file D:\Projects\eclipse\FindBugsExculde.xml with text <FindBugsFilter> <Match> <Class name="com.android.demo.notepad3.R$attr" /> </Match> </FindBugsFilter> I've added this file to Eclipse

force maven to fail the build on nonnull violations

百般思念 提交于 2019-11-29 12:10:42
I have the simple code below for testing the findbugs NonNull annotation with maven. I execute "mvn clean install site", and I get a directory target/site/css and target/site/images, but nothing more. I was expecting to get a report, saying that println(null) violates the NonNull condition. What do I need to do to get that report? Also, is there a way to prevent "mvn clean install" to succeed if there are NonNull violations? Note: I am aware that I can get such report with Sonar; However, I would like "mvn clean install" to fail if there are such errors, without the need to use an optional