skip to main content
research-article

Masked types for sound object initialization

Published:21 January 2009Publication History
Skip Abstract Section

Abstract

This paper presents a type-based solution to the long-standing problem of object initialization. Constructors, the conventional mechanism for object initialization, have semantics that are surprising to programmers and that lead to bugs. They also contribute to the problem of null-pointer exceptions, which make software less reliable. Masked types are a new type-state mechanism that explicitly tracks the initialization state of objects and prevents reading from uninitialized fields. In the resulting language, constructors are ordinary methods that operate on uninitialized objects, and no special default value (null) is needed in the language. Initialization of cyclic data structures is achieved with the use of conditionally masked types. Masked types are modular and compatible with data abstraction. The type system is presented in a simplified object calculus and is proved to soundly prevent reading from uninitialized fields. Masked types have been implemented as an extension to Java, in which compilation simply erases extra type information. Experience using the extended language suggests that masked types work well on real code.

References

  1. Kevin Bierhoff and Jonathan Aldrich. Modular typestate checking of aliased objects. In Proc. 22nd ACM Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA), pages 301--320, October 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Patrice Chalin and Perry James. Non-null references by default in Java: Alleviating the nullity annotation burden. In Proceedings of the 21st European Conference on Object-Oriented Programming, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Sigmund Cherem and Radu Rugina. Maintaining doubly-linked list invariants in shape analysis with local reasoning. In Verification, Model Checking, and Abstract Interpretation, 8th International Conference (VMCAI 2007), Nice, France, January 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Robert DeLine and Manuel F¨ahndrich. Enforcing high-level protocols in low-level software. In Proc. SIGPLAN 2001 Conference on Programming Language Design and Implementation, pages 59--69, June 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Robert DeLine and Manuel Fähndrich. Typestates for objects. In Proceedings of 18th European Conference on Object-Oriented Programming (ECOOP'04), 2004.Google ScholarGoogle ScholarCross RefCross Ref
  6. Torbjörn Ekman and G¨orel Hedin. Pluggable checking and inferencing of non-null types for java. Journal of Object Technology, 6(9):455--475, October 2007.Google ScholarGoogle ScholarCross RefCross Ref
  7. Manuel Fähndrich and K. Rustan M. Leino. Declaring and checking non-null types in an object-oriented language. In Proc. 2003 ACM Conference on Object-Oriented Programming Systems, Languages, and Applications (OOSPLA), pages 302--312, October 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Manuel Fähndrich and K. Rustan M. Leino. Heap monotonic typestate. In Proceedings of the first International Workshop on Alias Confinement and Ownership (IWACO), July 2003.Google ScholarGoogle Scholar
  9. Manuel Fähndrich and Songtao Xia. Establishing object invariants with delayed types. In Proc. 22nd ACM Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA), October 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Stephen Fink, Eran Yahav, Nurit Dor, G. Ramalingam, and Emmanuel Geay. Effective typestate verification in the presence of aliasing. In ISSTA '06: Proceedings of the 2006 international symposium on Software testing and analysis, pages 133--144, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Kathleen Fischer and John Reppy. The design of a class mechanism for Moby. In Proc. SIGPLAN 1999 Conference on Programming Language Design and Implementation, pages 37--49, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification. Addison Wesley, 3rd edition, 2005. ISBN 0321246780. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. David Hovemeyer and William Pugh. Finding bugs is easy. In OOPSLA '04: Companion to the 19th annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, pages 132--136, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. David Hovemeyer, Jaime Spacco, and William Pugh. Evaluating and tuning a static analysis to find null pointer bugs. In PASTE '05: Proceedings of the 6th ACM SIGPLAN-SIGSOFT workshop on Program analysis for software tools and engineering, pages 13--19, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Atsushi Igarashi and Benjamin C. Pierce. On inner classes. In Informal Proceedings of the Seventh International Workshop on Foundations of Object-Oriented Languages (FOOL 7), Boston, MA, January 2000.Google ScholarGoogle ScholarCross RefCross Ref
  16. ECMA International. Eiffel analysis, design and programming language. ECMA Standard 367, June 2005.Google ScholarGoogle Scholar
  17. Haskell 98: A non-strict, purely functional language, February 1999. Available at http://www.haskell.org/onlinereport/.Google ScholarGoogle Scholar
  18. Anita K. Jones and Barbara Liskov. A language extension for expressing constraints on data access. Comm. of the ACM, 21(5):358--367, May 1978. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. JSR 308: Annotations on Java Types. Available at http://groups.csail.mit.edu/pag/jsr308/.Google ScholarGoogle Scholar
  20. K. Rustan M. Leino. Data groups: specifying the modification of extended state. In Proc. 13th ACM Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA), pages 144--153, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. B. Liskov and J. Guttag. Data abstraction. In Abstraction and Specification in Program Development, chapter 4, pages 56--98. MIT Press and McGraw Hill, 1986.Google ScholarGoogle Scholar
  22. Barbara Liskov, Dorothy Curtis, Mark Day, Sanjay Ghemawat, Robert Gruber, Paul Johnson, and Andrew C. Myers. Theta Reference Manual. Programming Methodology Group Memo 88, MIT Laboratory for Computer Science, Cambridge, MA, February 1994. Available at http://www.pmg.lcs.mit.edu/papers/thetaref/.Google ScholarGoogle Scholar
  23. J. M. Lucassen and D. K. Gifford. Polymorphic effect systems. In Proc. 15th ACM Symp. on Principles of Programming Languages (POPL), pages 47--57, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, Cambridge, MA, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Greg Morrisett, David Walker, Karl Crary, and Neal Glew. From System F to typed assembly language. ACM Transactions on Programming Languages and Systems, 21(3):528--569, May 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Nathaniel Nystrom, Michael R. Clarkson, and Andrew C. Myers. Polyglot: An extensible compiler framework for Java. In Proc. 12th International Compiler Construction Conference (CC'03), pages 138--152, April 2003. LNCS 2622. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Xin Qi and Andrew C. Myers. Masked types. Technical report, Computer and Information Science, Cornell University, October 2008. http://hdl.handle.net/1813/11563.Google ScholarGoogle Scholar
  28. Joel Richardson, Peter Schwarz, and Luis-Felipe Cabrera. CACL: Efficient fine-grained protection for objects. In Proc. 1992 ACM Conference on Object-Oriented Programming Systems, Languages, and Applications, pages 154--165, Vancouver, BC, Canada, October 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Amie L. Souter and Lori L. Pollock. The construction of contextual def-use associations for object-oriented systems. IEEE Trans. Softw. Eng., 29(11):1005--1018, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Amie L. Souter, Lori L. Pollock, and Dixie Hisley. Inter-class def-use analysis with partial class representations. In PASTE '99: Proceedings of the 1999 ACM SIGPLAN-SIGSOFT workshop on Program analysis for software tools and engineering, pages 47--56, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Robert E. Strom and Shaula Yemini. Typestate: A programming language concept for enhancing software reliability. IEEE Transactions on Software Engineering (TSE), 12(1):157--171, January 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Sun Microsystems. Java Language Specification, version 1.0 beta edition, October 1995. Available at ftp://ftp.javasoft.com/docs/javaspec.ps.zip.Google ScholarGoogle Scholar
  33. Don Syme. Initializing mutually referential abstract objects: The value recursion challenge. Electronic Notes in Theoretical Computer Science, 148(2):3--25, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Reinhard Wilhelm, Shmuel Sagiv, and Thomas W. Reps. Shape analysis. In Proc. 9th International Compiler Construction Conference (CC'00), pages 1--17, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Andrew K. Wright and Matthias Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1):38--94, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Masked types for sound object initialization

              Recommendations

              Comments

              Login options

              Check if you have access through your login credentials or your institution to get full access on this article.

              Sign in

              Full Access

              PDF Format

              View or Download as a PDF file.

              PDF

              eReader

              View online with eReader.

              eReader
              About Cookies On This Site

              We use cookies to ensure that we give you the best experience on our website.

              Learn more

              Got it!