Inference of Field Initialization

Fausto Spoto and Michael D. Ernst
Università di Verona, Italy; University of Washington, USA
Program Surfing I

A raw object is partially initialized, with only some fields set to legal values. It may violate its object invariants, such as that a given field is non-null. Programs often manipulate partially-initialized objects, but they must do so with care. Furthermore, analyses must be aware of field initialization: proving the absence of null pointer dereferences or of division by zero, or proving that object invariants are satisfied, requires initialization information.

We present a static analysis that infers a safe over-approximation of the program elements that might hold raw objects. We have proved the analysis sound and implemented it in a tool called Julia. We have evaluated Julia on over 160K lines of code. We compared its output to manually-written initialization and nullness information, and to an independently-written type-checking tool that checks initialization and nullness. Julia's output is accurate and, we believe, useful both to programmers and to static analyses.