views:

45

answers:

2

Is there a quick way (e.g. tool) to detect, from the source (or maybe even from compiled classes), which parts of an application call Java API methods that are only implemented in a specific Java version? (e.g. which parts of my app are Java6-specific)

I don't necessarily want to hop through all ClassMismatchErrors and avoid the trial-and-error-method. Let's say I only want to document which parts of an application won't work if they were writte for, e.g., Java6 and I want to run it in a version 5 JDK.

Is there something like this? Google did not help this time, nor did I find any solution here (a rare case indeed:)

+3  A: 

The Animal Sniffer might be helpful for this, especially its Maven plugin.

Pascal Thivent
wow this is exactly what I was searching for, thanks for the quick and helpful answer!Hudson is really a great piece of software, not only as a CI server, it seems:)
Gregor
btw the project has moved to Codehaus, where already version 1.5 is available:http://mojo.codehaus.org/animal-sniffer-maven-plugin/
Gregor
A: 

If I understand you correctly, what you're describing doesn't sound like a very good idea to me.

It sounds like you want to build some library on JDK 6 (specifying -target 1.5), but let it be run on JDK 5 and just have certain classes or methods here and there just not work (because they needed a Java6-only API). I wouldn't do this. A method which should work might still trigger a class to be loaded which itself contains some reference to a class that's new in Java 6, and an Error will be thrown.

It's much better if you just choose which version is your minimum supported version and live with that.

Kevin Bourrillion
Thanks for the additional food for thought, Kevin. I did not mean to write new software that gracefully degrades from JDK6 to JDK5 (however this could be really useful, saving that Animal Sniffer caters for dependencies in the way you described).I was searching for a tool to analyze existing code to give me a quick overview about what will work and what won't when deploying the JDK6-app in question on a JDK5-environent, sothat I can estimate what changes would be necessary to adapt to the older version.
Gregor