Java resource management: please help to understand Findbugs results.

Posted by java.is.for.desktop on Stack Overflow See other posts from Stack Overflow or by java.is.for.desktop
Published on 2010-03-14T10:42:13Z Indexed on 2010/03/14 10:45 UTC
Read the original article Hit count: 262

Filed under:
|
|
|

Hello, everyone!

Findbugs bugs me about a method which opens two Closeable instances, but I can't understand why.

Source

public static void sourceXmlToBeautifiedXml(File input, File output)
        throws TransformerException, IOException, JAXBException {

    FileReader fileReader = new FileReader(input);
    FileWriter fileWriter = new FileWriter(output);

    try {
        // may throw something
        sourceXmlToBeautifiedXml(fileReader, fileWriter);
    } finally {
        try {
            fileReader.close();
        } finally {
            fileWriter.close();
        }
    }
}

Findbugs analysis

Findbugs tells me

Method [...] may fail to clean up java.io.Reader [...]

and points to the line with FileReader fileReader = ...

Question

Who is wrong: me or Findbugs?

© Stack Overflow or respective owner

Related posts about findbugs

Related posts about java