我使用 Findbugs 插件运行 Eclipse Java EE juno SR2 win32。
下面的代码示例让 FindBugs 显示一个发现:
catch (OutOfMemoryError e) {
tryAgain = true;
log.error("try to recover", e);
System.gc(); // not so happy about this
}
这是描述
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)
那么我怎样才能将此行注释为不被检查?
我试过了(来源)
@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_GC")
System.gc();
这不起作用,所以我将其移至方法
@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_GC")
private bla(){
这就是说:“edu无法解析为一种类型”,所以我尝试了:
@SuppressWarnings("DM_GC")
private bla(){
我得到了一个“不支持的@SuppressWarnings(“DM_GC”)”
这不是关于解决 findbugs 错误的请求,而是关于如何禁用特定错误的请求。
谢谢!
仅供参考:我知道调用 gc 并不是一个好主意。