0

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.

oᴉɹǝɥɔ
  • 1,796
  • 1
  • 18
  • 31
  • I have found a similar question here, May be It can help you... http://stackoverflow.com/questions/11463327/is-this-a-memory-leak-or-a-false-positive – pbajpai Jun 15 '16 at 16:55
  • I found one more similar question: http://stackoverflow.com/questions/23459568/eclipse-inconsistencies-resource-leak-unassigned-closeable-value-is-never – pbajpai Jun 15 '16 at 16:56
  • Questions above are not similar at all. Those developers are lucky to have the compiler warnings triggered as expected. I don't get the warnings. PLEASE READ THE ACTUAL QUESTION :) My problem is I WANT those warnings to be produced but they are not. – oᴉɹǝɥɔ Jun 15 '16 at 17:01
  • Can you show the calling code in both cases? – nitind Jun 15 '16 at 17:03
  • Why? The calling code doesn't matter. I need my Eclipse compiler to produce "Resource leak" warnings on any code similar to the one I have in my question. The compiler seems to ignore the "Resource leak" warning setting in my environment. – oᴉɹǝɥɔ Jun 15 '16 at 17:06
  • 2
    Actually, this warning is not due to anything related to Java code, its a bug in eclipse, https://bugs.eclipse.org/bugs/show_bug.cgi?id=434065 I have tried to understand it, but not sure whether it is resolved or not, Anyway If its a bug, and then If you are not getting this warning which should not come in my opinion, then its good.. :) – pbajpai Jun 15 '16 at 17:09
  • Does the another developer have the same eclipse version as you? – Carlitos Way Jun 15 '16 at 17:14
  • @pbajpai21 Genius! The other developer upgraded Eclipse with patches for previous Eclipse version to support 1.8. I just told her to remove the patch and her Eclipse no longer produces the warning! You answered my question. – oᴉɹǝɥɔ Jun 15 '16 at 17:19
  • @Cherio,,Thanks ..happy coding... – pbajpai Jun 15 '16 at 17:22

0 Answers0