Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the latest JRE instead of older a Java versions, am I guaranteed it will work?

Tags:

java

Lets say I have a Java project that is coded with Java 1.5 and I'm using a later version of Java but set target to 1.5.

If the code compiles and tests OK with the later Java, am I then guaranteed that it will work the same on an actual Java 1.5 runtime?

Or will I need to install one version of all JRE that I depend on to be sure?

What happens with bugs in the JRE? If there is a bug in 1.5, that is fixed in 1.6. If I use Java 1.6 with target set to 1.5, will that bug affect me?

In a realistic scenario, is this a concern that I need to have at all?

like image 249
Fredrik Avatar asked Mar 05 '13 16:03

Fredrik


1 Answers

Assuming you set target and source to 1.5, you only need to be worried in three main cases I can think of:

  • You're using internal com.sun classes, which may have changed or disappeared (or relying on some other internal behaviour somehow.)

  • You're relying on buggy behaviour which was fixed in a later version.

  • You run into a backwards incompatible change (rare but it has been known to happen.)

    What happens with bugs in the JRE? If there is a bug in 1.5, that is fixed in 1.6. If I use Java 1.6 with target set to 1.5, will that bug affect me?

If the bug is in the libraries, then no it won't affect you. Target only really stipulates the version of the bytecode you compile against, you'll still be using the updated libraries. As said earlier, note however this could potentially cause issues if you rely on this buggy behaviour.

If there is a deliberate backwards incompatible change, then all cases I've seen of this present themselves as compile time errors rather than runtime errors, so they'll be trivial to spot (and usually pretty easy to fix as well.)

I'd still advocate testing on the new version of the JVM before you release, but in practice it's not usually a problem, in my experience anyway.

like image 53
Michael Berry Avatar answered Sep 25 '22 12:09

Michael Berry