10

Recently, we upgrade the Jdk version from 1.6 to 1.8 in one of my Java project. But there are some compilation or runtime errors, so I have to upgrade some libraries:

  • gradle: 1.9 to 1.10
  • spring: 3.x to 4.x

That because they are using some early versions of ASM, but which supports jdk 1.8 only from 5.x

Java said it is backward compatible, but why the original versions of libraries can't work with jdk 1.8 directly?

9
  • 7
    Java 8 bytecode will not run on a Java 6 JVM - that's not what backwards compatibility means. In the same way, Java 8 bytecode can't be processed by a library designed for Java 6 bytecode.
    – user253751
    Jan 30, 2015 at 2:54
  • 4
    @LưuVĩnhPhúc there are no new instructions, but that doesn't mean the bytecode format hasn't changed (and it has!)
    – user253751
    Jan 30, 2015 at 4:04
  • 3
    In straightforward terms, the ASM library deliberately and openly fails to comply with the prerequisites which the code must meet for binary compatibility guarantees to apply. Jan 30, 2015 at 8:46
  • 2
    @Lưu Vĩnh Phúc: it depends what you mean with the colloquial term “bytecode”. There are no new instructions, but the class file format has changed.
    – Holger
    Jan 30, 2015 at 9:11
  • 3
    @Rogério: depends on what you mean with “class file format”. The general structure hasn’t changed, there are only a new version number, new attributes and new definitions about what constructs are allowed/may appear at which places. That’s enough to make certain existing byte code parsing tools crash and that’s what the discussion was about. As a side note, even the fact that javac now uses the invokedynamic instruction, which isn’t a new Java 8 feature but unused in ordinary Java 7 code, caused several tools working with Java 7 code to fail on Java 8 code.
    – Holger
    May 6, 2015 at 9:18

2 Answers 2

13

ASM is a pretty low-level library.

It processes Java byte-code directly (whereas a "normal" application would just let the JVM load its classes). The byte-code format changes from time to time, and newer versions cannot be used by an older JVM.

Messing with JDK or class format internals is not covered by backwards compatibility.

This is really an edge-case, and ASM is pretty much the only "popular" example.


More importantly (and more common) though are slight behavioural changes in system library code. So your application will technically still run, but do things differently. Most of the time, you want that, as it means improvement (for example better performance), but sometimes it can cause bugs for you.

For example:


But all-in-all the legacy app compatibility story is really good with Java. They have to keep it in mind with all their enterprise customers.

4
11

Because ASM is a tool that operates on the Java byte-code. And the byte-code format changed to introduce new features. As such, you had to upgrade the tool to support the new byte-code.

Note, that software compiled with an older version of the JDK does not always work with newer versions of Java. For example, enum was not a keyword in early versions of the JDK.

11
  • 6
    About the enum keyword: That seems to only affect the compiler. If I had old code compiled with an enum class or field or method of my own, shouldn't it still work? It certainly should not have any effect if I used the new keyword as a local variable or parameter name.
    – Thilo
    Jan 30, 2015 at 3:00
  • 2
    @asteri: It is a keyword now. Before that, you could name your own things (classes, variables, methods) enum. Now you cannot anymore. As I result, the same code does not compile anymore with the new compiler (I am still dubious that it affects the runtime).
    – Thilo
    Jan 30, 2015 at 3:04
  • 3
    Sure it does. Compile this with -source 1.4. Still runs on Java7: public class enum{ public static void main(String[] argv){ System.out.println(1); } }
    – Thilo
    Jan 30, 2015 at 3:10
  • 5
    You said "software compiled with an older version of the JDK " and later clarified "thus the code compiled with Java 1.4 in that case would not work with Java 5+.". Of course, you cannot compile against it properly anymore, but it still runs. Binary compatibility for unchanged legacy applications.
    – Thilo
    Jan 30, 2015 at 3:12
  • 5
    @Thilo Failing with an exception against code violating its contract does not count as binary incompatibilty, though---the code's behavior was undefined to begin with. They made Thread#stop(Throwable) fail with UnsupportedOperationException---I think that's the strongest example yet of breaking binary compatibility. Jan 30, 2015 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.