java - How to fix pmd violation "NullAssignment"? -


pmd report nullassignment of following code, best practice fix it?

assigning object null code smell. consider refactoring.

the following code not written me, have question on why creating temporary timer instance, assign instance timer? starttimer , stoptimer used in multithread context.

private timer timer;  private void starttimer() {     if (timer == null) {         timer atimer = timerservice.createtimer(default_timer_value, null);         atimer.setlistener(this);         timer = atimer;     } }  private void stoptimer() {     if (timer != null) {         timer atimer = timer;         timer = null;         atimer.cancel();         atimer.setlistener(null);     } }  public void start() {   synchronized(..) {      starttimer();   } }  public void stop() {   synchronized(..) {      stoptimer();   } } 

this code written in false believe reference set null garbage collected faster.

therefore message pmd false believe coded.

this wrong assumption garbage collector runs when memory exhausted , collects objects have no reference left on them.

even calling system.gc() not cause garbage collector run. call merely hint garbage collector when garbage collector detemines enough free memory avaible not run.


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -