Eclipse+FindBugs - exclude filter files doesn't work
Asked Answered
L

4

8

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 filter files" section.

But when I right-click on my project and select "Find Bugs" -> "Find Bugs" I still see the error

The class name com.android.demo.notepad3.R$attr doesn't start with an upper case letter

I have even tried to replace

<Class name="com.android.demo.notepad3.R$attr" />

with

<Class name="~.*" />

but still the error is there.

I tried to restart Eclipse - no luck. I even thought that maybe there is a Bug in FindBugs so it doesn't use the file specified but Procmon.exe from SysinternalsSuite shows that it do use it each time I execute FindBugs:

ProcessName Operation   Path                                    Result
javaw.exe   QueryOpen   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   QueryOpen   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CreateFile  D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CreateFile  D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   QueryFileInternalInformationFile D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CloseFile   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   ReadFile    D:\Projects\eclipse\FindBugsExculde.xml SUCCESS
javaw.exe   CloseFile   D:\Projects\eclipse\FindBugsExculde.xml SUCCESS

What am I doing wrong? Please help me!

Lifelong answered 27/9, 2011 at 11:47 Comment(0)
O
22

Following the directives from Jenkins I created a findbugs-exclude.xml in my android workspace and added it via Eclipse -> Window -> Preferences -> Java -> FindBugs -> Filter files -> "Add..." button near the "Exclude filter files" section to findbugs. My first error was that I ticked the first checkbox (the include filter :-) section).

Then I started manually findbugs and everything was ok. The content of my file is:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Class name="~.*\.R\$.*"/>
    </Match>
    <Match>
    <Class name="~.*\.Manifest\$.*"/>
    </Match>
</FindBugsFilter>

I am using eclipse 3.7.1 and findbugs 1.3.9. Hope that helps.

Ovenware answered 12/10, 2011 at 17:17 Comment(0)
S
2

Filter file may be ignored silently when path to file is incorrect or when XML file is not valid. Try to validate filter using XSD from https://raw.githubusercontent.com/findbugsproject/findbugs/master/findbugs/etc/findbugsfilter.xsd .

Had this problem on Eclipse 4.4.2.

Soteriology answered 7/2, 2018 at 12:27 Comment(0)
E
2

I just want to remind newbie that "Default Settings" is apply on new project, so you can't just exclude your filter in "Default Settings" if you want to apply it in current project:

enter image description here

instead you should exclude your filter in "Settings":

enter image description here

btw, once plugin installed and restart, Android Studio may pop up dialog on right bottom, you just have to click that link Add R.class File Filter, it will automatically generate the correct xml code for you.

enter image description here

enter image description here

Emeritaemeritus answered 1/8, 2018 at 8:42 Comment(1)
I guess my original question is now irrelevant given that Android Studio is based on JetBrains IntelliJ instead of Eclipse. But hopefully your answer will help someone googling for similar issues, so I’ve upvoted :)Lifelong
R
0

Please delete the error manually. Select the error and right click, select Delete. Then rebuild your project.

It could be that findbugs is ignoring the file correctly, but that doesn't mean that the errors it has previously raised on the file get deleted, they still exist, and you have to delete them manually.

Recognizor answered 27/9, 2011 at 12:21 Comment(1)
Unfortunately this is not the case :( I've tried to delete them as you suggested but they rise again next time I run "Find Bugs". I've also tried to clear the project - the errors go away - but if I run "Find Bugs" - they appear.Lifelong

© 2022 - 2024 — McMap. All rights reserved.