RLK.MAILRLK (Resource Leak) issues are reported when resources are allocated but not properly disposed after use. Failing to properly dispose a resource can lead to such problems as:
An RLK.MAIL warning indicates that a Java mail object is not closed on exit. Vulnerability and riskResources such as streams, connections and graphic objects must be explicitly closed. The close operation can unblock transactions or flush file changes in the file system. While a resource will eventually be closed by the garbage collector, resource exhaustion can occur before garbage collection starts. Depending on the nature of the resource, various exceptions will be thrown on a failed attempt to allocate another resource, for example: java.io.FileNotFoundException: Too many open files or too many database connections. Mitigation and preventionExplicitly close all resources that have the close method, even those that you think are not doing anything significant. Future code changes will then be safe from such errors. Example 120 public void printQuotas(Session s, URLName name) { 21 try { 22 IMAPStore store = new IMAPStore(s, name); // Store created 23 final Quota[] quotas = store.getQuota("key"); 24 for (int i = 0; i < quotas.length; i++) { 25 final Quota quota = quotas[i]; 26 System.out.println("quota: " + quota); 27 } 28 } catch (MessagingException e) { 29 System.err.println("Was not able to get quota: " + e.getMessage()); 30 } 31 } RLK.MAIL is reported for the snippet on line 22: IMAPStore 'store' is not closed on exit. ExtensionThis checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information. |