University of Cambridge > Talks.cam > Computer Laboratory Programming Research Group Seminar > Using the OpenJDK to investigate covariance in Java

Using the OpenJDK to investigate covariance in Java

Add to your list(s) Download to your calendar using vCal

If you have a question about this talk, please contact Dominic Orchard.

Note unusual day and time.

The Java type system is unsafe since it allows covariant use of arrays. For example, an array of Bananas can be used where an array of Fruit is expected, given that Banana is a subclass of Fruit. This allows the following unsafe code:

Banana[] bananas = new Banana[ 5 ];

Fruit[] fruits = bananas;

fruits[ 0 ] = new Apple(); // runtime exception

bananas[ 0 ]; // Apple?

In the above example, the programmer gets back an Apple where he was expecting Bananas, causing an undesired runtime exception.

We investigate the covariant use of arrays in open source Java programs to see whether programmers use this problematic feature of Java. We make use of the freely available OpenJDK, modifying its Java compiler to disallow covariant use of arrays, thus reporting any such uses as compile errors. We apply this compiler to a code corpus of 106 open source programs, including large and well-known programs such as Eclipse, JUnit and Ant.

Initial results of our investigation show that covariance is rarely used outside the context of legacy code and Java libraries. This leads us to question its relevance in the Java language.

In our talk, we also discuss solutions to covariance taken by other languages such as Scala and Google Dart, explain our modifications to the OpenJDK Java compiler and report the full results of our study.

This talk is part of the Computer Laboratory Programming Research Group Seminar series.

Tell a friend about this talk:

This talk is included in these lists:

Note that ex-directory lists are not shown.

 

© 2006-2024 Talks.cam, University of Cambridge. Contact Us | Help and Documentation | Privacy and Publicity