2

Im running Eclipse Java EE juno SR2 win32 with the Findbugs plugin.

Following codesample lets FindBugs display a finding:

catch (OutOfMemoryError e) {
     tryAgain = true;
     log.error("try to recover", e);
     System.gc(); // not so happy about this
}

And here is the discription

Bug: [..] forces garbage collection; extremely dubious except in benchmarking code

Code explicitly invokes garbage collection. Except for specific use in benchmarking, this is very dubious.

In the past, situations where people have explicitly invoked the garbage collector in routines such as close or 
finalize methods has led to huge performance black holes. Garbage collection can be expensive. Any situation that forces 
hundreds or thousands of garbage collections will bring the machine to a crawl.

Confidence: High, Rank: Of Concern (16)
Pattern: DM_GC 
Type: Dm, Category: PERFORMANCE (Performance)

So how can i annotate this row to not beeing checked?

I've tried (source)

@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_GC")
System.gc();

which isn't working so i moved it to the method

@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_GC")
private bla(){

which is saying : "edu cannot be resolved to a type" so i tried with:

@SuppressWarnings("DM_GC")
private bla(){

and i got a "Unsupported @SuppressWarnings("DM_GC")"

This is not a request about solving the findbugs bug, its how to disable specific bugs.

Thank you!

FYI: I'm know its not a really good idea to call gc.

Community
  • 1
  • 1
MemLeak
  • 4,456
  • 4
  • 45
  • 84

1 Answers1

4

"edu cannot be resolved to a type"

This is because you haven't added the FindBugs jar to your project. If you are using Maven add this dependency to you pom.xml:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>annotations</artifactId>
    <version>2.0.0</version>
</dependency>

If you don't use Maven add the jar manually to your classpath. Then the FindBugs annotation SuppressWarnings will be found and you shouldn't see the problem anymore.

Kai
  • 38,985
  • 14
  • 88
  • 103