Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/manual/faq.tex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
\\ \ref{faq-false-positive}: What is a ``false positive'' warning?
\\ \ref{faq-false-positive-extend-checker-framework}: How can I improve the Checker Framework to eliminate a false positive warning?
\\ \ref{faq-infer-fields}: Why doesn't the Checker Framework infer types for fields and method return types?
\\ \ref{faq-field-initializers}: Why are some operations legal in constructors but not in methods?
\\ \ref{faq-relationships-between-variables}: Why doesn't the Checker Framework track relationships between variables?
\\ \ref{faq-path-sensitive}: Why isn't the Checker Framework path-sensitive?

Expand Down Expand Up @@ -874,6 +875,44 @@
% programmers see inconsistent results, they should write types explicitly.


\subsectionAndLabel{Why are some operations legal in constructors but not in methods?}{faq-field-initializers}

Java permits you to initialize an instance field either in the constructor
or in a field initializer. The Checker Framework behaves as if the field
initializer assignments are performed at the beginning of the constructor
(after superclass construction), because that is how Java executes the
program.

Here is an example:

\begin{Verbatim}
class MyClass1 {
@Nullable Object field;
MyClass1() {
field = new Object();
field.toString(); // no possible NullPointerException
}
}

class MyClass2 {
@Nullable Object field = new Object(); // Same initialization as for MyClass1
MyClass2() {
field.toString(); // no possible NullPointerException
}
}

class MyClass3 {
@Nullable Object field;
void myMethod() {
field.toString(); // Nullness Checker warns: possible NullPointerException
}
}
\end{Verbatim}

For consistency, the Checker Framework treats the \<MyClass1> and
\<MyClass2> constructors the same.


\subsectionAndLabel{Why doesn't the Checker Framework track relationships between variables?}{faq-relationships-between-variables}

The Checker Framework estimates the possible run-time value of each
Expand Down