UF.ZIP

UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The UF.ZIP warning indicates an attempt to use a ZipFile after it was closed.

Example 1

18     public static final void copy(InputStream in, OutputStream out) throws IOException {
19         byte[] buffer = new byte[1024];
20         int len;
21 
22         while ((len = in.read(buffer)) >= 0) {
23             out.write(buffer, 0, len);
24         }
25 
26         in.close();
27         out.close();
28     }
29 
30     public final void unzip(final ZipFile zipFile) {
31         Enumeration entries;
32         entries = zipFile.entries();
33 
34         try {
35             while (entries.hasMoreElements()) {
36                 ZipEntry entry = (ZipEntry) entries.nextElement();
37 
38                 if (entry.isDirectory()) {
39                     final File dir = new File(entry.getName());
40                     dir.mkdir();
41                 } else {
42                     try {
43                         copy(zipFile.getInputStream(entry), new FileOutputStream(entry.getName()));
44                     } catch (IOException e) {
45                         zipFile.close();
46                     }
47                 }
48             }
49 
50             zipFile.close();
51         } catch (IOException e) {
52             // do nothing
53         }
54     }

UF.ZIP is reported for the snippet on line 43: 'zipFile' is closed on line 45 in case of an IOException, but there will be an attempt to access 'zipFile' on the next iteration of the cycle.