ObjectName与String FindBug错误不兼容

时间:2011-09-30 02:10:17

标签: java findbugs

对于我的生产代码,类似于以下内容:

public something xyz(String name) {
  return getSomething(abc.get(name));
}

如果方法“get”期望将javax.management.ObjectName传递给它,我将从Findbugs工具获得以下高优先级警告:

Bug: String is incompatible with expected argument type javax.management.ObjectName
Pattern id: GC_UNRELATED_TYPES, type: GC, category: CORRECTNESS

但是,根据javax API文档,我看到可以将ObjectName作为String,如下所示:http://download.oracle.com/javase/6/docs/api/javax/management/ObjectName.html

这是Findbugs的问题还是我错过了什么?

1 个答案:

答案 0 :(得分:4)

public something xyz(String name) {
    return getSomething(abc.get(new ObjectName(name)));
}