Thursday, October 2, 2014

Coverity Issues - JAVA


First of all, I am curious of how coverity finds a fault in code, by doing static analysis.
But in this article, I wish to cover
1) The variety of issues found by Coverity,
2) How to address each of them,
3) What is the rationale behind each of the issue?

1. Relating to Static Inner Classes:

SIC: Should be a static inner class (SIC_INNER_SHOULD_BE_STATIC)

For example, it flags that inner class should be made static.
 
package com.question.inner.stat;

public class ExperimentStatic {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub  
  ExperimentStatic.NestedClass expVar = new ExperimentStatic.NestedClass(3, "dfdpstr");
 }
 
 static class NestedClass{  
  private int i;
  private String str;  
  NestedClass(int id, String pstr)
  {
   i = id;
   str = pstr;
  }
 }
}