UF.ZIP

当尝试使用已被释放的资源时,就会报告 UF(使用已释放)问题。UF.ZIP 警告表明尝试在 ZipFile 已被关闭后使用它。

示例 1

复制
     public static final void copy(InputStream in, OutputStream out) throws IOException {
         byte[] buffer = new byte[1024];
         int len;
 
         while ((len = in.read(buffer)) >= 0) {
             out.write(buffer, 0, len);
         }
 
         in.close();
         out.close();
     }
 
     public final void unzip(final ZipFile zipFile) {
         Enumeration entries;
         entries = zipFile.entries();
 
         try {
             while (entries.hasMoreElements()) {
                 ZipEntry entry = (ZipEntry) entries.nextElement();
 
                 if (entry.isDirectory()) {
                     final File dir = new File(entry.getName());
                     dir.mkdir();
                 } else {
                     try {
                         copy(zipFile.getInputStream(entry), new FileOutputStream(entry.getName()));
                     } catch (IOException e) {
                         zipFile.close();
                     }
                 }
             }
 
             zipFile.close();
         } catch (IOException e) {
             // do nothing
         }
     }

针对第 43 行的代码段报告 UF.ZIP:已在第 45 行因 IOException 而关闭 zipFile,但是在循环的下一次迭代时又尝试访问 zipFile。