Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

UF.MAIL

UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The UF.MAIL warning indicates an attempt to use Java Mail API object after it was closed.

Example 1

13 public Collection<Message> getMessages(final Session session,
14                                    final String... folderNames) throws MessagingException {
15 final Collection<Message> result = new ArrayList<Message>();
16 Store store = session.getStore("pop3");
17 store.connect();
18 
19 for (String folderName : folderNames) {
20     Folder folder = getFolder(store, folderName);
21     if (folder != null) {
22         Message messages[] = folder.getMessages();
23         for (int i = 0, n = messages.length; i < n; i++) {
24             result.add(messages[i]);
25         }
26     }
27 }
28 
29 return result;
30 }
31 
32 private Folder getFolder(Store store, final String folderName) throws MessagingException {
33 if (folderName == null) {
34     return null;
35 }
36 
37 try {
38     Folder folder = store.getFolder(folderName);
39     folder.open(Folder.READ_ONLY);
40     return folder;
41 } catch (MessagingException e) {
42     store.close();
43 }
44 return null;
45 }

UF.MAIL is reported for the snippet on line 20: Java Mail API object 'store' is closed by method 'getFolder()' in case if MessagingException is thrown on line 38. This is a problem because on the next iteration of the cycle the method 'getFolder()' would be called once more and it will attempt to access the closed store.

Example 2

13 public Collection<Message> getMessages(final Session session,
14                                        final String... folderNames) throws MessagingException {
15     final Collection<Message> result = new ArrayList<Message>();
16     Store store = session.getStore("pop3");
17     store.connect();
18 
19     for (String folderName : folderNames) {
20         Folder folder = getFolder(store, folderName);
21         if (folder != null) {
22             Message messages[] = folder.getMessages();
23             for (int i = 0, n = messages.length; i < n; i++) {
24                 result.add(messages[i]);
25             }
26         }
27     }
28 
29     return result;
30 }
31 
32 private Folder getFolder(Store store, final String folderName) throws MessagingException {
33     if (folderName == null) {
34         return null;
35     }
36 
37     try {
38         Folder folder = store.getFolder(folderName);
39         folder.open(Folder.READ_ONLY);
40         return folder;
41     } catch (MessagingException e) {
42         store.close();
43         throw e;
44     }
45 }

The snippet from the previous section is fixed. Method 'getFolder()' re-throws the MessagingExcpetion now.