Bug 526270 - Source that works with JavaSE-1.8 does not compile with JavaSE-9
Summary: Source that works with JavaSE-1.8 does not compile with JavaSE-9
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7.1a   Edit
Hardware: All All
: P3 blocker (vote)
Target Milestone: 4.7.2   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-19 10:43 EDT by Dani Megert CLA
Modified: 2017-11-16 01:54 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2017-10-19 10:43:50 EDT
4.7.1a.

package p;

import javax.annotation.Resource;

public class HelloWorld {

	public static void main(String[] args) {
		Class<Resource> annoClazz = Resource.class;
		System.out.println(annoClazz);
		System.out.println("Hello World!");
	}
}


This compiles with JavaSE-1.8 but not with JavaSE-9.
Comment 1 Dani Megert CLA 2017-10-19 10:45:39 EDT
Compile error is:
The import javax.annotation.Resource cannot be resolved
Comment 2 Dani Megert CLA 2017-10-19 10:50:34 EDT
I tried to fix it manually, but no luck: I was able to specify the system library under the classpath node, but after reopening the Java Build Path dialog, the library is again under the module node.
Comment 3 Stephan Herrmann CLA 2017-10-19 11:13:56 EDT
Why do you expect this to work? 

JavaSE-9 is modular, and I don't see anything in JEP 261 that would allow putting the system library on the classpath. "Compatibility" is achieved solely via the unnamed module. 

With this, compile errors in previously OK programs are to be expected, in particular, JavaSE-9 does not provide access to type javax.annotation.Resource out of the box.

To make it accessible to the unnamed module you need to add-module java.xml.ws.annotation.

JRE System Library > Is modular > Edit ... > Contents > Move javax.xml.ws.annotation from left to right.

Re-compile and all is fine.

(Yes, this should be documented in places ...)
Comment 4 Dani Megert CLA 2017-10-19 11:21:27 EDT
(In reply to Stephan Herrmann from comment #3)
> Why do you expect this to work? 

Well, API compatibility? ;-) But I agree this is not "our" bug.


> (Yes, this should be documented in places ...)

I think even better would be a quick fix that finds and adds the module. WDYT?
Comment 5 Dani Megert CLA 2017-10-19 11:26:49 EDT
Two issues on our side:
- It is pretty hidden under the 'Is modular' node
- It's unexpected that I can add JavaSE-9 under classpath and then it gets moved to the module path without telling me. We should prevent that already at the beginning.

Good news is that we keep the module info and don't loose it if the user goes to 1.8 and back to 9.
Comment 6 Stephan Herrmann CLA 2017-10-19 12:55:43 EDT
(In reply to Dani Megert from comment #4)
> (In reply to Stephan Herrmann from comment #3)
> > (Yes, this should be documented in places ...)
> 
> I think even better would be a quick fix that finds and adds the module.
> WDYT?

bug 526277

(In reply to Dani Megert from comment #5)
> Two issues on our side:
> - It is pretty hidden under the 'Is modular' node

As this node is important for several tasks, I hope users well get used to it.

The only improvement I could think of right now: Place a new button/link into the Edit Library dialog, from where you can switch to the ModuleDialog.

> - It's unexpected that I can add JavaSE-9 under classpath and then it gets
> moved to the module path without telling me. We should prevent that already
> at the beginning.

Bug 526275
Comment 7 Dani Megert CLA 2017-10-19 13:09:49 EDT
(In reply to Stephan Herrmann from comment #6)

Thank you :-)
Comment 8 Jay Arthanareeswaran CLA 2017-11-16 01:54:03 EST
Verified for 4.7.2