Abstract
In this paper, we show that the unsoundness discovered by Amin and Tate (2016) in Java’s wildcards is avoidable, even in the absence of a nullness-aware type system. The key insight of this paper is that soundness in type systems that implicitly introduce existential types through subtyping hinges on still making sure there are suitable witness types when introducing existentially quantified type variables. To show that this approach is viable, this paper formalizes a core calculus and proves it sound. We used a static analysis based on our approach to look for potential issues in a vast corpus of Java code and found none (with 1 false positive). This confirms both that Java's unsoundness has minimal practical consequence, and that our approach can avoid it entirely with minimal false positives.
- Nada Amin and Ross Tate. 2016. Java and Scala’s Type Systems Are Unsound: The Existential Crisis of Null Pointers. In Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016). Association for Computing Machinery, New York, NY, USA. 838–848. isbn:9781450344449 https://doi.org/10.1145/2983990.2984004
Google Scholar
Digital Library
- Nicholas Cameron, Sophia Drossopoulou, and Erik Ernst. 2008. A Model for Java with Wildcards. In ECOOP 2008 – Object-Oriented Programming, Jan Vitek (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 2–26. isbn:978-3-540-70592-5 https://doi.org/10.1007/978-3-540-70592-5_2
Google Scholar
Digital Library
- Patrice Chalin and Perry R. James. 2007. Non-Null References by Default in Java: Alleviating the Nullity Annotation Burden. In Proceedings of the 21st European Conference on Object-Oriented Programming (ECOOP’07). Springer-Verlag, Berlin, Heidelberg. 227–247. isbn:3540735887 https://doi.org/10.1007/978-3-540-73589-2_12
Google Scholar
Cross Ref
- Sophia Drossopoulou, Susan Eisenbach, and Sarfraz Khurshid. 1999. Is the Java type system sound? Theory and Practice of Object Systems, 5, 1 (1999), 3–24. https://doi.org/10.1002/(SICI)1096-9942(199901/03)5:1<3::AID-TAPO2>3.0.CO;2-T
Google Scholar
Cross Ref
- Manuel Fähndrich and K. Rustan M. Leino. 2003. Declaring and Checking Non-Null Types in an Object-Oriented Language. In Proceedings of the 18th Annual ACM SIGPLAN Conference on Object-Oriented Programing, Systems, Languages, and Applications (OOPSLA ’03). Association for Computing Machinery, New York, NY, USA. 302–312. isbn:1581137125 https://doi.org/10.1145/949305.949332
Google Scholar
Digital Library
- Manuel Fähndrich and Songtao Xia. 2007. Establishing Object Invariants with Delayed Types. In Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA ’07). Association for Computing Machinery, New York, NY, USA. 337–350. isbn:9781595937865 https://doi.org/10.1145/1297027.1297052
Google Scholar
Digital Library
- Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. 1998. Classes and Mixins. In Proceedings of the 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’98). Association for Computing Machinery, New York, NY, USA. 171–183. isbn:0897919793 https://doi.org/10.1145/268946.268961
Google Scholar
Digital Library
- James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Alex Buckley, Daniel Smith, and Gavin Bierman. 2021. The Java Language Specification: Java SE 17 Edition. https://docs.oracle.com/javase/specs/jls/se17/html/index.html
Google Scholar
- Robert Harper. 2016. Practical Foundations for Programming Languages (2nd ed.). Cambridge University Press, USA. isbn:1107150302
Google Scholar
Digital Library
- Atsushi Igarashi, Benjamin C. Pierce, and Philip Wadler. 2001. Featherweight Java: A Minimal Core Calculus for Java and GJ. ACM Trans. Program. Lang. Syst., 23, 3 (2001), May, 396–450. issn:0164-0925 https://doi.org/10.1145/503502.503505
Google Scholar
Digital Library
- Fengyun Liu, Ondřej Lhoták, Aggelos Biboudis, Paolo G. Giarrusso, and Martin Odersky. 2020. A Type-and-Effect System for Object Initialization. Proc. ACM Program. Lang., 4, OOPSLA (2020), Article 175, Nov., 28 pages. https://doi.org/10.1145/3428243
Google Scholar
Digital Library
- Abel Nieto, Yaoyu Zhao, Ondřej Lhoták, Angela Chang, and Justin Pu. 2020. Scala with Explicit Nulls. In 34th European Conference on Object-Oriented Programming (ECOOP 2020), Robert Hirschfeld and Tobias Pape (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 166). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 25:1–25:26. isbn:978-3-95977-154-2 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2020.25
Google Scholar
Cross Ref
- Matthew M. Papi, Mahmood Ali, Telmo Luis Correa, Jeff H. Perkins, and Michael D. Ernst. 2008. Practical Pluggable Types for Java. In Proceedings of the 2008 International Symposium on Software Testing and Analysis (ISSTA ’08). Association for Computing Machinery, New York, NY, USA. 201–212. isbn:9781605580500 https://doi.org/10.1145/1390630.1390656
Google Scholar
Digital Library
- Benjamin C. Pierce. 2002. Types and Programming Languages. The MIT Press, Cambridge, MA, USA. isbn:0262162091
Google Scholar
- Daniel Smith and Robert Cartwright. 2008. Java Type Inference is Broken: Can We Fix It? In Proceedings of the 23rd ACM SIGPLAN Conference on Object-Oriented Programming Systems Languages and Applications (OOPSLA ’08). Association for Computing Machinery, New York, NY, USA. 505–524. isbn:9781605582153 https://doi.org/10.1145/1449764.1449804
Google Scholar
Digital Library
- Alexander J. Summers and Peter Mueller. 2011. Freedom before Commitment: A Lightweight Type System for Object Initialisation. In Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’11). Association for Computing Machinery, New York, NY, USA. 1013–1032. isbn:9781450309400 https://doi.org/10.1145/2048066.2048142
Google Scholar
Digital Library
- Ross Tate. 2013. Mixed-Site Variance. In FOOL ’13: Informal Proceedings of the 20th International Workshop on Foundations of Object-Oriented Languages. https://fool2013.cs.brown.edu/tate.pdf
Google Scholar
- Ross Tate, Alan Leung, and Sorin Lerner. 2011. Taming Wildcards in Java’s Type System. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’11). Association for Computing Machinery, New York, NY, USA. 614–627. isbn:9781450306638 https://doi.org/10.1145/1993498.1993570
Google Scholar
Digital Library
- Mads Torgersen, Erik Ernst, and Christian Plesner Hansen. 2005. Wild FJ. In FOOL: Foundations of Object-Oriented Languages. https://homepages.inf.ed.ac.uk/wadler/fool/program/14.html
Google Scholar
Index Terms
Wildcards need witness protection
Recommendations
Taming wildcards in Java's type system
PLDI '11: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and ImplementationWildcards have become an important part of Java's type system since their introduction 7 years ago. Yet there are still many open problems with Java's wildcards. For example, there are no known sound and complete algorithms for subtyping (and ...
Taming wildcards in Java's type system
PLDI '11Wildcards have become an important part of Java's type system since their introduction 7 years ago. Yet there are still many open problems with Java's wildcards. For example, there are no known sound and complete algorithms for subtyping (and ...
Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed types
Bidirectional typechecking, in which terms either synthesize a type or are checked against a known type, has become popular for its applicability to a variety of type systems, its error reporting, and its ease of implementation. Following principles ...






Comments