资源泄漏:“unassigned closeable value”从未关闭

nue99wik  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(239)

如果我有以下代码:

public XNameSupport implements AutoCloseable {
   private String localName;
   public String getLocalName(){
       return localName;
   }
}
public XElementSupport implements AutoCloseable {
   private XNameSupport name = new XNameSupport("root");
   private List<XElementSupport> child = new ArrayList<XElementSupport>();
   public XNameSupport getName(){
       return name;
   }
   Iterable<XElementSupport> elements(String name) throws Exception {
        List<XElementSupport> elements = new ArrayList<XElementSupport>();
        for (XElementSupport element : child) {
            if (element.getName().localName.equals(name))//Resource leak: '<unassigned Closeable value>' is not closed at this location
                elements.add(element);
        }
        return elements;
    }

在element.getname().localname下;并显示以下警告:
资源泄漏:“unassigned closeable value”从未关闭
如果我通过getlocalname()方法访问localname,警告就会消失。我在现场收到了警告。这是eclipse中的不一致(bug?),还是我遗漏了这两个场景之间的一些基本区别?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题