Affiliation:
1. ETH Zurich, Zürich, Switzerland
Abstract
One of the main purposes of object initialisation is to establish invariants such as a field being non-null or an immutable data structure containing specific values. These invariants are then implicitly assumed by the rest of the implementation, for instance, to ensure that a field may be safely dereferenced or that immutable data may be accessed concurrently. Consequently, letting an object escape from its constructor is dangerous; the escaping object might not yet satisfy its invariants, leading to errors in code that relies on them. Nevertheless, preventing objects entirely from escaping from their constructors is too restrictive; it is often useful to call auxiliary methods on the object under initialisation or to pass it to another constructor to set up mutually-recursive structures.
We present a type system that tracks which objects are fully initialised and which are still under initialisation. The system can be used to prevent objects from escaping, but also to allow safe escaping by making explicit which objects might not yet satisfy their invariants. We designed, formalised and implemented our system as an extension to a non-null type system, but it is not limited to this application. Our system is conceptually simple and requires little annotation overhead; it is sound and sufficiently expressive for many common programming idioms. Therefore, we believe it to be the first such system suitable for mainstream use.
Publisher
Association for Computing Machinery (ACM)
Subject
Computer Graphics and Computer-Aided Design,Software
Cited by
8 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. Initialization patterns in Dotty;Proceedings of the 9th ACM SIGPLAN International Symposium on Scala;2018-09-17
2. Practical Void Safety;Lecture Notes in Computer Science;2017
3. Towards a model of corecursion with default;Proceedings of the 18th Workshop on Formal Techniques for Java-like Programs;2016-07-17
4. An Experimental Evaluation of Deliberate Unsoundness in a Static Program Analyzer;Lecture Notes in Computer Science;2015
5. Let’s verify this with Why3;International Journal on Software Tools for Technology Transfer;2014-04-19