Sonar violation: “Method may fail to close stream on exception”

前端 未结 4 1402
青春惊慌失措
青春惊慌失措 2021-01-28 00:15

I have this method:

 private void unZipElementsTo(String inputZipFileName, String destPath) throws FileNotFoundException, IOException {

        OutputStream out         


        
4条回答
  •  [愿得一人]
    2021-01-28 00:51

    To avoid masking an exception with an exception during the close of the streams It's often recommended to "hide" any io exception in the finally.

    To fix use the org.apache.commons.io.IOUtils.closeQuietly(...) or guava Closeables.html#closeQuietly(java.io.Closeable) in the finally close

    more on exception handling issues :
    http://mestachs.wordpress.com/2012/10/10/through-the-eyes-of-sonar-exception-handling/

提交回复
热议问题