Skip to main content

Can't Go to the 1.5 Bleeding Edge? Bring it Back to 1.4!

Posted by jdcmember on May 19, 2005 at 5:05 PM PDT

Retroweaver 1.1 is a post-compile bytecode fixup tool. With it, Java 5 language features (enum types, varargs, auto-boxing, generics) will run on any 1.4 VM. Neat trick brought to you by Toby Reyelts.

Backport175 is a JSR 175 (Java Class and class member annotations) implementation for pre-1.5 VMs by Jonas Boner and Alexandre Vasseur. Out of the box, it supports using special JavaDoc tags and special post-compilation steps to embed Java 5 class and class member annotations in to compiled bytecode. Add to that a runtime annotation reader library that's forward and backward compatible with pre- and post-1.5, so the same reader code works in either enviroment. Another neat trick!

Putting the two together, you get something very cool. You compile normal Java 5 classes with annotations using a Java 5 compiler, then use Retroweaver to make the classes 1.4 compatible. Using the Backport175 implementation then to read the annotations (no special Backport175 post-compilation or special JavaDoc tags necessary).

The only trick is that after 1.5 compilation, you need to re-compile all you @interfaces as normal Java interfaces. (Extra work necessary if you depend on @interface default values.)

Using these two together, my next plan is to backport JAXB 2.0 to work on a 1.4 VM. Discussing the idea on the DevelopMentor ADVANCED-JAVA list, Vlad Roubstav in a very practical tone of voice said "...But
if I were talking to an engineer at work trying to sell me on a solution architecture with 1.5 bytecode retrofitters in it, I would just laugh because no 2.0-1.0 delta can be worth deploying bytecode-manipulated draft RIs...
". But I can't resist the temptation...

(Vlad, you have a homepage or blog?)