Master’s Thesis Presentation • Programming Languages • Towards Safe Initialization of Scala Global Objects

Friday, December 5, 2025 2:00 pm - 3:00 pm EST (GMT -05:00)

Please note: This master’s thesis presentation will take place in DC 2314.

Enze Xing, Master’s candidate
David R. Cheriton School of Computer Science

Supervisor: Professor Ondřej Lhoták

This thesis focuses on safe initialization of global objects in Scala. Global objects encapsulate global information in Scala, and their initialization are susceptible to causing run-time errors. Moreover, global objects are initialized by demand (i.e. on their first access). The initialization safety of a global object is brittle if it depends on the initialization point of the object, which can occur in the entire program. This motivates the idea of automatically detecting potential initialization errors during compilation.

The main contribution of this thesis is designing and implementing a global object initialization checker in the Scala compiler. Theoretically, we identified run-time errors caused by unsafe initialization patterns of global objects and organized three static principles to enforce on Scala programs: Prohibiting accesses to uninitialized fields, which prevents null pointer exceptions; partial ordering of global object initialization order, which prevents deadlocks between locks that guard the initialization of global objects; and initialization-time irrelevance, which ensures that initialization safety of the global object is independent of the initialization point. We then designed the global object initialization checker by proposing the formal initialization semantics of a Scala initialization calculus, and the initialization checker is presented as an abstract interpreter of the initialization calculus. The initialization checker also checks the initialization process of each global object individually rather than conducting a whole-program analysis.

Practically, we have integrated the abstract interpreter into the Scala compiler after extending the initialization semantics with more Scala features. The initialization checker can be turned on when compiling Scala programs, and we evaluated the initialization checker during the compilation of many widely-used open-source Scala projects which form a test suite. The initialization checker reports warnings in several projects that are verified to be true positives. The result highlights the necessity of checking the initialization safety of Scala projects and the utility of the global object initialization checker in this thesis.