Speakers | |
---|---|
Raoul-Gabriel Urma | |
Janina Voigt | |
Schedule | |
Day | Saturday |
Room | K.4.401 |
Capacity | 85 |
Start time | 14:00 |
End time | 14:30 |
Duration | 00:30 |
Info | |
Track | Free Java Devroom |
Using the OpenJDK to investigate covariance in Java
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.
Concurrent events:
Next (up to 3) talks in the same room (K.4.401):
When | Event | Track |
---|---|---|
14:30-15:00 | Politics, Positives, Paperwork and Pain - Our year to date in the JCP | Free Java |
15:30-16:00 | Java in the Age of the JVM | Free Java |
16:00-16:30 | Introducing Mutability Detector | Free Java |