I have a simple Java class as below:
public static class NullInputStream extends InputStream {
public static InputStream wrap(InputStream src) {
return src == null ? new NullInputStream() : src;
}
@Override
public int read() throws IOException {
return -1;
}
}
This code is compiled in Eclipse 4.5
with Java compliance level 1.8
. The strange thing is happening. In my environment the compiler produces no warnings. Another developer gets the "Resource leak: '<unassigned Closeable value>' is never closed
" compiler warning warning on new NullInputStream()
. We determined that the warning must be triggered when "Resource leak
" is set to "Warning
" and goes away when it is dropped to "Ignore
". In my Eclipse
environment the warning is never triggered regardless of "Resource leak
" setting.
I spent hours trying to find the reason why the warning doesn't get triggered. I did export/import of compiler preferences from another developer environment, I triple-checked I don't use project specific settings, checked java compiler versions, runtimes, facets etc. - everything is 1.8
Note. My question is about this specific compiler warning not triggered and not the class design. I need the warning to be triggered. Other warnings e.g. "Dead code
" and "Potential resource leak
" work and trigger as expected.