Master’s thesis: Refactoring Java with CLP: making existing code generic
Intro
For my studies as master in computer science, I wrote a thesis titled:
“Refactoring Java with CLP: making existing code generic“.
Summary
Generics is a new feature in Java 1.5 where types get type parameters. A lot of existing code doesn’t use this feature yet. In my thesis I describe a method to automaticly add type parameters to code.
We start from code without type parameters which uses generic classes. Where these generic classes are used, we derive the appropriate type parameter, and add it to the code. In the resulting program types are specified more exact, and we can eliminate many casts. This improves code quality for the programmer, but has no effect on what the code does when executed.
The biggest difference between our system and the existing ones is that we support deriving wildcard types. This leads to better results: we can eliminate more casts, and get more general, reusable code. This is implemented using Constraint Logic Programming (CLP), more specificly CHR.
References
Some related papers:
- Donovan – Converting Java Programs to Use Generic Libraries
- von Dincklage – Converting Java Classes to Use Generics
- Fuhrer – Efficiently refactoring Java applications to use generic libraries
Other interesting links:
Java compiler bugs
When doing research related to my thesis, the following bugs were discovered in the Sun Java Compiler:
- 6450290: Capture of nested wildcards causes type error
- 6450691: Wrong capture of a ?-extends wildcard with a ?-super wildcard as bound
- 6495506: Cast inserted by generics can cause IllegalAccessError
- 6514483: Compiler NPE with impossible generic type
- 6526842: Another type system loophole in wildcard substitution