Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 519777

Summary: Java 1.7 projects fail to load if a dependent library specifies 1.8
Product: [Eclipse Project] JDT Reporter: Leo Ufimtsev <lufimtse>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.8   
Target Milestone: 4.8 M1   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Bug Depends on:    
Bug Blocks: 519340    
Attachments:
Description Flags
Stacktrace screenshot
none
screenshot showing jdk
none
screenshot showing jdk on Linux
none
Screenshot of JREs OSX(left), Linux(right)
none
Project none

Description Leo Ufimtsev CLA 2017-07-17 13:22:29 EDT
Steps to reproduce:
- Create eclipse project
- Set Java environment to 1.7
- Download latest SWT jar file from:
  http://download.eclipse.org/eclipse/downloads/
  (note, SWT library is now 1.8)
- Create a simple snippet like:

 import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SwtSnip {
	public static void main(String[] args) {
		Display display = new Display ();
		Shell shell = new Shell(display);
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}

- Run snippet


Expected result:
- A simple shell should be shown.
- This works on Linux/Gtk


Actual result:
- On OSX, exception is thrown:
  Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/swt/widgets/Display : Unsupported major.minor version 52.0
  (see screen shot)

Environment:
- MacOS Sierra 10.12.3
- Build Photon 4.8 2017/7/17th.
Comment 1 Leo Ufimtsev CLA 2017-07-17 13:22:58 EDT
Created attachment 269393 [details]
Stacktrace screenshot
Comment 2 Stephan Herrmann CLA 2017-07-17 14:07:24 EDT
(In reply to Leo Ufimtsev from comment #1)
> Created attachment 269393 [details]
> Stacktrace screenshot

Unfortunately, in this screenshot the About dialog hides the line starting "<terminated> ...", in which we'd see which JRE was used for the launch.

If that launch uses a JRE 1.7, failing to load a Java-8-compiled class is totally expected.

Question: how did you launch on Linux? So, the interesting part is not the compiler compliance, but the JRE configured for run/debug.
Comment 3 Leo Ufimtsev CLA 2017-07-18 10:09:20 EDT
Created attachment 269404 [details]
screenshot showing jdk
Comment 4 Leo Ufimtsev CLA 2017-07-18 10:21:38 EDT
Created attachment 269406 [details]
screenshot showing jdk on Linux
Comment 5 Leo Ufimtsev CLA 2017-07-18 10:23:12 EDT
Attaching console screenshot from mac and linux.

Interestingly, on Linux it shows 1.8, but on Mac it shows 1.7.

Hmmm, not sure, but on Win/Linux, the mechanism is smart enough to launch java 8 if there is a java 8 dependency somewhere, where as on Mac it seems to launch the jvm that is specified in the project. 
I'm not sure if this is specific to eclipse or java on OS X thou?
Comment 6 Stephan Herrmann CLA 2017-07-18 12:48:36 EDT
Leo, what JREs have you registered in Preferences > Java > Installed JREs?

Which JRE is used to run Eclipse on the different platforms?
Comment 7 Leo Ufimtsev CLA 2017-07-18 13:00:39 EDT
Created attachment 269411 [details]
Screenshot of JREs OSX(left), Linux(right)

On both my OSX and Linux I have 1.8. See screenshot.

Thoughts?
Comment 8 Leo Ufimtsev CLA 2017-07-18 13:02:43 EDT
Created attachment 269413 [details]
Project

I'm attaching an example project so you can reproduce issue locally easier.

Extract it and import it into your workspace, then try to run the only .java file in the project. You will see it fails on OSX. If you increase JRE to 1.8 in project setting, it works.

Let me know if I can help further.
Comment 9 Stephan Herrmann CLA 2017-07-18 13:07:26 EDT
(In reply to Leo Ufimtsev from comment #7)
> Created attachment 269411 [details]
> Screenshot of JREs OSX(left), Linux(right)
> 
> On both my OSX and Linux I have 1.8. See screenshot.
> 
> Thoughts?

Yep, this explains:

On Linux you have *only* 1.8, so whatever the project says, debug can only use this one JRE and everything works - *accidentally*.

On MacOS you have both 1.7 & 1.8 so the project setting of 1.7 tells JDT to associate the 1.7 JRE to that project, both for compiling and running.

If you want to keep the project at 1.7 you need to update your launch configuration to explicitly select the 1.8 JRE.
Comment 10 Leo Ufimtsev CLA 2017-07-18 13:23:19 EDT
Ah, I see. Interesting.

Thank you for figuring this one out. If I remove the unchecked 1.7 on OSX, then it works.
Comment 11 Sasikanth Bharadwaj CLA 2017-08-01 02:06:11 EDT
Verified for 4.8 M1 using I20170731-2000 build