|
Evolving Java-based APIs ... The nightmare of binary compatibility!
[
vmassol
]
I have been coding in java for the past 6 years and I thought I knew the language and platform quite well. Well, two days ago I was proved wrong as I discovered a new facet of it that I wasn't aware of: binary compatibility... There is a good article called Evolving Java-based APIs by Jim des Rivieres. It's a complex subject that not a lot of persons are aware of and which is extremely important if you're a framework writer. Let me give one example. Imagine you have a Now, if you think you can safely refactor the Indeed, code that has been compiled with the first version of the framework will
have a reference to What it means is that preserving binary compatibility is difficult and is something that strongly impacts how you design your APIs. Using delegation has to be preffered over class inheritance as it will allow you to change the implementation without breaking binary compatibility. That's what was new to me. So far I had been designing simply using the OO concepts and choosing the pattern the most adapted. Now, I've discovered that I also need to introduce the binary compatibility aspect in the picture and that it drives my design choices! Evolving Java-based APIs is really difficult... Is anybody aware of a tool that takes two jars A and B and determines if A is a drop-in replacement for B, i.e. checks binary compatibility of a jar with an older version? Would be so cool to catch these kind of problems in continuous integration... --Lars Kühne, July 15, 2003 06:55 AM
I'm not familiar with such as tool... It would be indeed very cool. I guess it can be done with simply JUnit: Steps: What do you think? Has anyone done this before? -Vincent --Vincent Massol, July 29, 2003 04:59 PM
Not exactly what I was aiming at, but I guess this is what happens when you can't stop thinking about JUnit in Action ;-) What I had in mind was an Ant task that takes two jars, "latest release" and "compilation result", and compares their public API on the byte code level, using a library like BCEL. Upsides of this approach: The "latest release" does not have to be in CVS, it can be a file or downloaded from any URL, e.g. from a server like the maven ibiblio repository. Writing Unit tests is not required. That's a big plus for projects like GUI libraries where it's hard to write unit tests (or maybe it isn't - can't wait to read your book). The build process is much easier. Just fire up an additional Ant task and provide the location of your latest release. No need to recompile with old jar, no need to manage any class path issues. I follow the IDEA plugin development list, it seems that Timur Zambalayev has a tool to monitor API changes, see http://www.intellij.net/forums/thread.jsp?forum=23&thread=36605&tstart=0&trange=15 Don't know which tool he uses, if it can handle this problem, or if it can be used in CI and break the build for incompatible changes. If we can't find out or if his tool doesn't have a reasonable license, I guess this could be a nice new little project on sourceforge. --Lars Kühne, August 1, 2003 07:24 AM
Just thought I'd let you know that I have started writing that thing and simple stuff is working: I could use some help, though - feel free to contact me if you're interested. --Lars Kühne, August 17, 2003 07:13 PM
Hi Lars, I think it's an excellent idea. It looks very similar to jdiff (http://jdiff.sourceforge.net/). Actually I can only see 2 main differences: I'm sure you've seen that Timur has posted his source code (on the same thread). The main difference with your idea and what I had in mind when I started this topic is that I was talking about binary compatibility whereas you are talking about API compatibility. But I do agree, API compatbility is already a nice step forward and having a check for API compatibility as part of the build process looks very promising. Actually I can envision a process where any API change would have to be explicitely documented possibly as nested items in the Ant task you're envisioning. Then some processing could generate an XML/HTML file describing the API changes. The idea would be that anything not described would be considered a build error. Cool stuff! --Vincent Massol, August 17, 2003 09:33 PM
Honestly, it will be way easier to implement such comparison tool using ASM. --eu, July 6, 2004 12:38 PM
Post a comment
|