Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force warning when class is not closed

When I work with IO classes like java.util.Scanner or java.io.BufferedReader, Eclipse displays a warning Resource leak: 'suchAndSuch' is never closed. How can I make Eclipse display this warning for my own class when it is not closed?

What I want to know is if there is an Interface or something I need to implement to make my class be treated like the IO classes, so that it's independent of any one IDE, e.g. the command line javac also displays a warning when a resource isn't closed.

like image 445
jpyams Avatar asked Aug 10 '15 13:08

jpyams


1 Answers

Eclipse gives warning "never closed" for any class which implements java.io.Closeable

class X implements Closeable {
    @Override
    public void close() throws IOException {
    }
}

...
    public static void main(String[] args) throws IOException {
        X x = new X(); <-- Eclipse warning
    }
like image 139
Evgeniy Dorofeev Avatar answered Oct 13 '22 17:10

Evgeniy Dorofeev