Have there been incompatibilities between Java releases where Java source code/Java class files targeting Java version X won't compile/run under version Y (where Y > X) ?
By "Java release" I mean versions such as:
- JDK 1.0 (January, 1996)
- JDK 1.1 (February, 1997)
- J2SE 1.2 (December, 1998)
- J2SE 1.3 (May, 2000)
- J2SE 1.4 (February, 2002)
- J2SE 5.0 (September, 2004)
- Java SE 6 (December, 2006)
House rules:
- Please include references and code examples where possible.
- Please try to be very specific/concrete in your answer.
- A class that is being marked as @Deprecated does not count as a backwards incompatibility.
The semantics of the memory model changed from 1.4 to 1.5. It was changed to allow besides other things double checked locking again. (I think volatile semantics were fixed.) It was broken.
See report on API changes for the JRE class library here: http://abi-laboratory.pro/java/tracker/timeline/jre/
The report includes backward binary- and source-compatibility analysis of Java classes.
The report is generated by the japi-compliance-checker tool.
...
Another interesting analysis for JDK 1.0-1.6 you can find at Japitools JDK-Results page.
As Sean Reilly said, a new method can break your code. Besides the simple case that you have to implement a new method (this will produce a compiler warning) there is a worst case: a new method in the interface has the same signature as a method you do already have in your class. The only hint from the compiler is a warning that the
@Override
annotation is missing (Java 5 for classes, the annotation is supported for interfaces in Java 6 but optional).Obviously the naming convention of release names is not backwards-compatible.
(The list is from Wikipedia.)
Yet another example of java.sql breaking compatibility:
In 1.5 a compareTo(Date) method was added to java.sql.Timestamp. This method would throw a ClassCastException if the supplied Date was not an instance of java.sql.Timestamp. Of course, java.sql.Timestamp extends Date, and Date already had a compareTo(Date) method that worked with all Dates, so this meant that code that compared a Timestamp to a (non-Timestamp) Date would break at runtime in 1.5.
It's interesting to note that it appears that 1.6 seems to have fixed this problem. While the documentation for java.sql.Timestamp.compareTo(Date) still says "If the argument is not a
Timestamp
object, this method throws aClassCastException
object", the actual implementation says otherwise. My guess is that this is a documentation bug.The following will compile under Java 1.4 but not Java 1.5 or later.
(Java 5 introduced 'enum' as a keyword. Note: it will compile in Java 5 if the "-source 1.4" option is provided.)