Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does checkstyle complain about this?

I have a class field which is a data object. Why does checkstyle complain about "write occurrence of b" and what does it mean ? The doSomething1() is always called before doSomething()

public class A{
  private B b;
  public void doSomething() {
    if(b!=null) {
      b.setYear(2012);
      b.setDay("Tuesday");
   } 
  }
  public void doSomething1(){
    b = new B();
    b.setDate(new Date());
  }
}
like image 919
Phoenix Avatar asked Jan 15 '23 10:01

Phoenix


1 Answers

It is not Checkstyle that this is coming from, but Eclipse itself.

If you highlight a property of your class, it will show you occurrences of that property in the class, with markers in the right-hand scroll bar. These are yellow, like the Checkstyle markers.

It will highlight instances where the property is read ("Occurrence of X") and where that property could be written to ("Write occurence of X"), for instance if you pass it into a method as a parameter.

You can see where the message is configured http://grepcode.com/file/repository.grepcode.com/java/eclipse.org/3.5.2/org.eclipse.jdt/ui/3.5.2/org/eclipse/jdt/internal/ui/search/SearchMessages.properties

like image 75
matt freake Avatar answered Jan 24 '23 13:01

matt freake