Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Wildcards need witness protection

Published: 31 October 2022 Publication History

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.

References

[1]
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
[2]
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
[3]
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
[4]
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
[5]
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
[6]
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
[7]
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
[8]
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
[9]
Robert Harper. 2016. Practical Foundations for Programming Languages (2nd ed.). Cambridge University Press, USA. isbn:1107150302
[10]
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
[11]
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
[12]
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
[13]
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
[14]
Benjamin C. Pierce. 2002. Types and Programming Languages. The MIT Press, Cambridge, MA, USA. isbn:0262162091
[15]
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
[16]
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
[17]
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
[18]
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
[19]
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

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 6, Issue OOPSLA2
October 2022
1932 pages
EISSN:2475-1421
DOI:10.1145/3554307
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 31 October 2022
Published in PACMPL Volume 6, Issue OOPSLA2

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Existential Types
  2. Java Wildcards
  3. Null

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 446
    Total Downloads
  • Downloads (Last 12 months)140
  • Downloads (Last 6 weeks)14
Reflects downloads up to 14 Jan 2025

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media