eclipse – Why a java iterator can cause resource leak?

The code below generates warning in eclipse:

    Iterator<Document> it = docs.iterator();

    return new Iterator<String>() {

        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public String next() {
            Document doc = it.next();
            return doc.getString("url");
        }
    };

The warning message is : Potential resource leak: ‘it’ may not be closed at this location

The initial iterator is returned by mongo java API. The reason why I’m coding this is that I don’t want to expose the mongo API.

Why does eclipse display this warning ? How to get rid of it ?

Read more here: Source link