Bug 131382 - Compiler compliance level 1.4 still allows 1.5 API to go through
Summary: Compiler compliance level 1.4 still allows 1.5 API to go through
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: usability
Depends on:
Blocks:
 
Reported: 2006-03-10 14:39 EST by Christophe Cornu CLA
Modified: 2007-12-11 07:25 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Cornu CLA 2006-03-10 14:39:41 EST
Eclipse 3.2 M4 with 1.5 JRE

Did a code completion on Collections.s
Got Collections.emptyList(). Which is 1.5 specific. Broke head for 1.4 users.
Correct version was Collections.EMPTY_LIST

Is there a workaround? Or do you just guarantee bytecode is 1.4 but can't do anything but the java class libraries themselves?

Thanks,
Chris
Comment 1 Christophe Cornu CLA 2006-03-10 14:41:58 EST
> Did a code completion on Collections.s
typo. I meant 'Did a code completion on Collections.e'
Comment 2 Philipe Mulet CLA 2006-03-10 15:22:41 EST
If you put 1.5 classlibs on your classpath, then you get completions which maybe 1.5 specific. We are not excluding 1.5 specific constructs, simply because we don't really know what level they are.

In 1.4 target mode, we issue 1.4 classfiles, which are guaranteed to use any 1.5 constructs in their sources, but if you compiled them against 1.5 libs,  then you might have 1.5 binary dependencies from thereon.

So though you produced 1.4 classfiles, they will need a 1.5 JRE to be executed, due to the dependencies you did introduce. 

Best for 1.4 compliance to use 1.4 libs on your classpath, unless you like to live dangerously.

Closing as invalid.
Comment 3 Tod Creasey CLA 2007-07-16 07:58:44 EDT
I think this is a serious usability problem. I just did the same thing and almost borke a nightly build, if Kevin had not stayed late that night and caught it we would have been broken for several days (Cheers Kev).

org.eclipse.ui.ide has it's compiler compliance set to 1.4. I am using a 1.6 VM. I accidentally used some 1.6 API and released it to the ide plug-in.

We should at least have a warning marker generated that I am using API that is not compatible with the compliance level of our code - there is no way a user is going to figure this out on their own.
Comment 4 Christophe Cornu CLA 2007-07-16 11:17:54 EDT
Probably would require a custom JRE version checking tool that knows about the official public API's and their JRE requirement. That's some work...
Comment 5 Olivier Thomann CLA 2007-07-16 11:30:02 EDT
You might start by properly settings your installed JRE. You installed a JRE1.4 and you set it as an exact match. It should be picked up as the JRE of your project.
Comment 6 Philipe Mulet CLA 2007-07-16 11:54:36 EDT
Darin - can't execution environment help us here ? I would expect some access rules to kick in in such a scenario ?
Comment 7 Darin Wright CLA 2007-07-16 12:02:41 EDT
The access rules for execution environments only go to the class level - not methods within classes. If access rules supported finer granularity, we could potentially expand the rules.
Comment 8 Martin Aeschlimann CLA 2007-07-17 06:20:06 EDT
Would it make sense to introduce a stricter mode for the compiler where the compiler tests that the classfile compatibility of the used JARs is not higher than the configured source/classfile compliance?
Genereate an error: 'Trying to compiler 1.4 source against a 1.5 library'.
Comment 9 Tod Creasey CLA 2007-07-17 08:40:17 EDT
There would be a problem then in mixing plug-ins. For instance I am using Eclipse but developing another plug-in with 1.5 compliance so I would get errors if there were a mix of compliance levels in my setup.

However an error that flags me using an API with a higher than specified compliance level would be ideal.
Comment 10 Philipe Mulet CLA 2007-10-10 05:19:13 EDT
Re: comment 8
There is already a build preferences for checking incompatible required libraries.
Comment 11 Philipe Mulet CLA 2007-10-10 05:25:35 EDT
Re: comment 9
Once API tooling defines a set of rules, we should leverage these as (finer-grain) access rules, or something along these lines; for JDT users to see leveraged as they code.
Comment 12 Philipe Mulet CLA 2007-11-15 06:51:03 EST
Given option already exist as per comment 10, and API tooling is around the corner to go after such issues, I don't think we should invest more in compiler support.

Right now, the real answer is to make sure to have the proper level of libs on your classpath (and to detect inconsistencies, enable the option mentioned in comment 10).

No further action planned.
Is that ok?
Comment 13 Tod Creasey CLA 2007-11-15 08:56:26 EST
Philippe when you say have the proper level of libs on your classpath  do you mean only use Foundation libs? No good for us as we have a mix of compiler levels.


If you have something better on the way I agree we should just wait for this but I am not sure how to easily set up your solution so that we don't continually have this problem.
Comment 14 Philipe Mulet CLA 2007-11-15 09:06:33 EST
I personally have installed several JREs on my machine. Foundation 1.0, Java4, Java5 and Java6 (amongst others).
Given this, with required execution environments properly set on my projects, each of them is picking the right flavor at compile time (through JREContainer resolution).

This guarantees that each project is compiled against the right library.

As you observed indeed, there is no one JRE to rule them all...
Comment 15 Martin Aeschlimann CLA 2007-11-15 09:28:59 EST
Would it make sense to set the 'incompatible required libraries' to 'warning' by default?
Comment 16 Tod Creasey CLA 2007-11-15 10:27:33 EST
I would be happy to set to error myself - this is what we would do in our project preferences. But warning is a good start
Comment 17 Philipe Mulet CLA 2007-11-16 07:51:10 EST
I wouldn't change its default, because of the lib packaging issue (not us, but libs causing grief).

Java4 means target 1.2 in 1.3 source mode. However, some of the standard libs are stamped as 1.4, hence from the compiler standpoint it looks like these are incompatible with the fact you want to deliver code to a 1.2 target...

Ideally, the JRE container should rule these libs out of the classpath, to ensure that you do not accidentally code against them and really mean to deliver code for 1.2 targets. In reality, not many people do code for target prior to 1.4, so the glitch is tolerable, but still the warning would be kind of proeminent.
Comment 18 Frederic Fusier CLA 2007-12-11 07:25:52 EST
Verified for 3.4M4