10

Can anybody tell me the jsr14 target option of javac will be still available with JDK7/8?

Say,

$ javac -source 1.5 -target jsr14 Hello.java
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Jin Kwon
  • 2,005
  • 3
  • 15
  • 15

3 Answers3

12

We are heavily using -jsr14 in OSGi because it allows us to use generics in our API but still deploy on 1.4 environments, which are still popular in embedded. Unfortunately, they made JDK 7 not backward compatible with Java 6 and 5. Javac 1.7 ignores the generic information that is actually present in the JAR files. There is fortunately no problem at run-time as this info is ignored anyway. And it is not as if this was some undocumented feature ...

Unfortunately, people at the front often have very little regard for the people that cannot just update to the latest and the greatest. Guess Oracle really does not care about the embedded markets anymore.

We will likely now have to ship two JARs, one for the embedded and one for JDK 7. Sucks.

This is the bug report we filed: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7078419

Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Eclipse P2 uses the jsr14 target for a similar reason. Unfortunately, it is not true that there's no problem at runtime. OpenJDK blows up when using reflection on types that were compiled with jsr14 target. This is especially problematic when using Spring DM or Blueprint as seen here: https://gist.github.com/1251497 – mpilquist Sep 29 '11 at 18:23
  • 1
    I ran in this OSGi issue. Is there an OSGi bug report I can vote for? Note: the resolution for the JDK bug report is: Not a Defect It has to be fixed on OSGi side then. – Puce Mar 11 '12 at 16:41
  • I've filed an issue here: https://issues.apache.org/jira/browse/FELIX-3455 Please vote for it. – Puce Apr 12 '12 at 14:55
4

The latest OpenJDK source bundle (openjdk-7-ea-src-b130-18_feb_2011.zip) still contains the flag in the source (langtools/src/share/classes/com/sun/tools/javac/jvm/Target.java), but it has never been supported, so relying on it is a bad idea.

Why do you need it?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • Because I used to write 1.5 codes and compile for 1.4 target for my Java ME STBoxes. – Jin Kwon May 02 '11 at 11:32
  • 4
    @Jin: I'd use one of the supported targets and use something like [Retroweaver](http://retroweaver.sourceforge.net/) or [Retrotranslator](http://retrotranslator.sourceforge.net/) to post-process the result. – Joachim Sauer May 02 '11 at 11:34
4

That flag has been abandoned since the beta stages of 1.5. It was only included to allow the 1.5 beta compiler to bypass generics checking/parsing by default while the generics specification wasn't finalised. Once 1.5 was released, that flag became meaningless. New compiler versions may not give errors on encountering it but will most likely silently ignore it.

jwenting
  • 5,505
  • 2
  • 25
  • 30