nullable - Annotating reentrancy with Java Checker Framework's Nullness Checker -



nullable - Annotating reentrancy with Java Checker Framework's Nullness Checker -

i'm trying out checker framework's nullness checker java 8. when run checker on next code:

import java.util.hashmap; import java.util.map; import org.checkerframework.checker.nullness.qual.nullable; class { public void f() {} } public class foo { private map<a,integer> map = new hashmap<>(); private @nullable x; public void setx(@nullable x) { this.x = x; } public void call() { if (x != null) { map.put(x, 0); x.f(); } } }

the checker gives warning on x.f();: dereference of possible null-reference x. makes sense, of course. checker framework doesn't know map.put does. map object might have reference this, , phone call setx(null) on it.

now question following. there way tell checker framework method not modify object other object it's called on? because map.put doesn't phone call setx method, value of x not change.

to rid of warning, alter phone call method to:

public void call() { y = x; if (y != null) { map.put(y, 0); y.f(); } }

now there no warnings. makes sense: local variable cannot accessed outside. not introduce local variable sole purpose of getting rid of warning.

alternatively, annotate field x @monotonicnonnull. in actual utilize case maintain possibility of setting field null.

thanks in advance!

your question gives several first-class ways suppress warning, know doing.

however, want improve way. want know how create checker framework never issue warning in first place. key question is:

is there way tell checker framework method not modify object other object it's called on?

unfortunately, checker framework not have functionality. manual section 21.4.3, "side effects, determinism, purity, , flow-sensitive analysis", discusses how checker framework indicates purity or freedom side effects. @sideeffectfree , @pure annotations all-or-nothing.

your suggestion of partial purity annotations useful: create checker framework more expressive , cut down need suppress warnings, required. (on other hand, 1 more thing users learn; there expressiveness-complexity tradeoff.) suggest propose feature checker framework developers.

java nullable checker-framework

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -