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

Bug 521843

Summary: [9] Cannot launch JUnit Plugin test with Java 9 instead of Java 8
Product: [Eclipse Project] JDT Reporter: Till Brychcy <register.eclipse>
Component: DebugAssignee: Sarika Sinha <sarika.sinha>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: daniel_megert, jarthana, sarika.sinha, Vikas.Chandra
Version: 4.8   
Target Milestone: 4.7.1a   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/104302
https://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=303ab53c0c4e979c5c5a8b414f451afe90979685
https://git.eclipse.org/r/105597
https://git.eclipse.org/r/105598
https://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=5dc3b41e97884a94e4037ca7ae78bc4a7c4d962c
Whiteboard:
Bug Depends on:    
Bug Blocks: 522633    

Description Till Brychcy CLA 2017-09-04 15:37:17 EDT
DESCRIPTION:
Using a nested eclipse running the JAVA_BETA9 branch on a workspace with another copy of the JAVA_BETA9 branch,
launch org.eclipse.jdt.core.tests.model.Java9ElementTests als JUnit Plugin test.

No test will be executed, because the projects JRE is Java 8 and this Test needs a java 9 JRE.

Switch the JRE in the the launch configuration's "Main"-Tab  to "Java SE 9 [9]" and launch it.

The launch fails:
"-Xbootclasspath is no longer a supported option.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit."

ANALYSIS:
In org.eclipse.jdt.launching.StandardClasspathProvider.computeUnresolvedClasspath(ILaunchConfiguration), org.eclipse.jdt.launching.JavaRuntime.computeUnresolvedRuntimeDependencies(IJavaProject) is used for the entries, but
org.eclipse.jdt.launching.JavaRuntime.computeJREEntry(IJavaProject) to get the JRE.

Because of this the "entry.equals(projEntry)" never matches, because the projEntry has IRuntimeClasspathEntry.STANDARD_CLASSES, but the
entry for the JRE has IRuntimeClasspathEntry.CLASS_PATH

PATCH:
Use org.eclipse.jdt.launching.JavaRuntime.computeModularJREEntry(IJavaProject) to get the project's JRE
Comment 1 Eclipse Genie CLA 2017-09-04 15:40:51 EDT
New Gerrit change created: https://git.eclipse.org/r/104302
Comment 2 Sarika Sinha CLA 2017-09-04 23:48:14 EDT
Thanks Till!!
Comment 4 Sarika Sinha CLA 2017-09-21 05:29:43 EDT
Reopening this,
Adding Vikas from PDE as plain junit tests and java applications are working.
Comment 5 Sarika Sinha CLA 2017-09-21 11:11:50 EDT
I investigated further -
JUnitLaunchConfigurationDelegate in PDE Launching sets the classpath and bootclasspath.

All the jars for path are actually set to bootclasspath.

Even if JDT Launching stops the bootpath setting and avoids -Xbootclasspath error, it will not have the jars on the path and it fails(I tried out).

For java9 configurations, either everything should go to classpath or be set on classpath and modulepath.
Comment 6 Jay Arthanareeswaran CLA 2017-09-21 13:01:34 EDT
(In reply to Sarika Sinha from comment #5)
> I investigated further -
> JUnitLaunchConfigurationDelegate in PDE Launching sets the classpath and
> bootclasspath.
> 
> All the jars for path are actually set to bootclasspath.
> 
> Even if JDT Launching stops the bootpath setting and avoids -Xbootclasspath
> error, it will not have the jars on the path and it fails(I tried out).

Can we redirect such entries to classpath if the target VM is 9 or above? I know it's still not accurate, but if the clients of launch are unaware that -Xbootclasspath is not allowed, they are probably not aware of module path either, in which case, only place it can go to is classpath? Does it sounds reasonable?
Comment 7 Sarika Sinha CLA 2017-09-21 23:51:19 EDT
I thought about it Jay yesterday itself, but I could not find any place where there is a suggestion from Java9 that what was going in bootclasspath should go to classpath. May be this will be true for many cases but jdt launching can not bluntly just move it across. And only the respective component can provide exact order for paths.

The components who want to support the1r launches with java9 need to react.
Comment 8 Vikas Chandra CLA 2017-09-22 04:08:38 EDT
On the launched eclipse workspace, I dont see this issue.

On the base eclipse, I always get

java.net.SocketException: Socket operation on nonsocket: configureBlocking
	at java.net.DualStackPlainSocketImpl.configureBlocking(Native Method)
	at java.net.DualStackPlainSocketImpl.socketAccept(Unknown Source)
	at java.net.AbstractPlainSocketImpl.accept(Unknown Source)
	at java.net.PlainSocketImpl.accept(Unknown Source)
	at java.net.ServerSocket.implAccept(Unknown Source)
	at java.net.ServerSocket.accept(Unknown Source)
	at org.eclipse.jdi.internal.connect.SocketTransportService.accept(SocketTransportService.java:98)
	at org.eclipse.jdi.internal.connect.SocketTransportImpl.accept(SocketTransportImpl.java:60)
	at org.eclipse.jdi.internal.connect.SocketListeningConnectorImpl.accept(SocketListeningConnectorImpl.java:164)



Sometimes launch is not successful. ( not consistent way to recreate this) but if there is a mix of java8 plugins/project and java9 plugins/projects, it happens sometimes. Unfortunately I don't have a consistent way to recreating this.


I am really not sure what is happening.
Comment 9 Eclipse Genie CLA 2017-09-22 04:35:13 EDT
New Gerrit change created: https://git.eclipse.org/r/105597
Comment 10 Till Brychcy CLA 2017-09-22 04:37:47 EDT
(In reply to Eclipse Genie from comment #9)
> New Gerrit change created: https://git.eclipse.org/r/105597

I don't have time for a real analysis now, but I saw you are still researching this, so I thought, I'd post this patch (in jdt.debug), which fixes the problem, at least for the case I reported.
Comment 11 Vikas Chandra CLA 2017-09-22 04:42:51 EDT
Sometimes I get this error while launching ( debug launch) eclipse after creating a pde project with java 9 and 1 junit test case in it

This is the launching error I get sometimes

!STACK 1
org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:410)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createDefaultHeadlessContext(E4Application.java:491)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createDefaultContext(E4Application.java:505)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:204)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:614)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1472)
Caused by: java.lang.NoClassDefFoundError: javax/annotation/PostConstruct
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)
	... 23 more
Caused by: java.lang.ClassNotFoundException: javax.annotation.PostConstruct cannot be found by org.eclipse.e4.core.di_1.6.100.v20170421-1418
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:433)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
	... 25 more

!ENTRY org.eclipse.e4.ui.workbench 4 0 2017-09-22 14:07:11.908
!MESSAGE FrameworkEvent ERROR
!STACK 0
java.lang.NoClassDefFoundError: javax/annotation/PreDestroy
	at org.eclipse.e4.core.internal.di.InjectorImpl.disposed(InjectorImpl.java:450)
	at org.eclipse.e4.core.internal.di.Requestor.disposed(Requestor.java:156)
	at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:78)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:111)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.handleInvalid(TrackableComputationExt.java:74)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.dispose(EclipseContext.java:178)
	at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.dispose(EclipseContextOSGi.java:99)
	at org.eclipse.e4.core.internal.contexts.osgi.EclipseContextOSGi.bundleChanged(EclipseContextOSGi.java:141)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112)
	at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168)
	at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)
	at org.eclipse.osgi.container.Module.doStop(Module.java:634)
	at org.eclipse.osgi.container.Module.stop(Module.java:498)
	at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:202)
	at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:165)
	at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.ClassNotFoundException: javax.annotation.PreDestroy cannot be found by org.eclipse.e4.core.di_1.6.100.v20170421-1418
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:433)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
Comment 12 Sarika Sinha CLA 2017-09-22 04:46:59 EDT
(In reply to Till Brychcy from comment #10)
> (In reply to Eclipse Genie from comment #9)
> > New Gerrit change created: https://git.eclipse.org/r/105597
> 
> I don't have time for a real analysis now, but I saw you are still
> researching this, so I thought, I'd post this patch (in jdt.debug), which
> fixes the problem, at least for the case I reported.


Thanks Till.
This just stops the Xbootclasspath error. But required jars has to be put on the path like nirmal JUnit test case getClasspath() does. PDE getClasspath() just returns equinox in the path. It needs to add up the other classpath entries.
Comment 13 Sarika Sinha CLA 2017-09-22 04:47:46 EDT
(In reply to Vikas Chandra from comment #11)
> Sometimes I get this error while launching ( debug launch) eclipse after
> creating a pde project with java 9 and 1 junit test case in it
> 
> This is the launching error I get sometimes
> 
> !STACK 1
> org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError:
> javax/annotation/PostConstruct
> 	at
> org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:
> 410)
> 	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
> 	at
> org.eclipse.e4.core.contexts.ContextInjectionFactory.
> make(ContextInjectionFactory.java:162)
> 	at
> org.eclipse.e4.ui.internal.workbench.swt.E4Application.
> createDefaultHeadlessContext(E4Application.java:491)
> 	at
> org.eclipse.e4.ui.internal.workbench.swt.E4Application.
> createDefaultContext(E4Application.java:505)


You need to add  --add-modules=ALL-SYSTEM in vm arguments
https://marketplace.eclipse.org/content/java-9-support-beta-oxygen
Comment 14 Jay Arthanareeswaran CLA 2017-09-22 04:55:35 EDT
One question that I have: Why don't I see this in the last week's Y build?
Comment 15 Till Brychcy CLA 2017-09-22 04:57:50 EDT
(In reply to Sarika Sinha from comment #12)
> (In reply to Till Brychcy from comment #10)
> > (In reply to Eclipse Genie from comment #9)
> > > New Gerrit change created: https://git.eclipse.org/r/105597
> > 
> > I don't have time for a real analysis now, but I saw you are still
> > researching this, so I thought, I'd post this patch (in jdt.debug), which
> > fixes the problem, at least for the case I reported.
> 
> 
> Thanks Till.
> This just stops the Xbootclasspath error. But required jars has to be put on
> the path like nirmal JUnit test case getClasspath() does. PDE getClasspath()
> just returns equinox in the path. It needs to add up the other classpath
> entries.

Hmm with this patch, the tests launch successfully for me.

So I guess there is another problem for a setup which different as described in comment #0, if yes, maybe there should be another bug for this?
Comment 16 Eclipse Genie CLA 2017-09-22 05:03:30 EDT
New Gerrit change created: https://git.eclipse.org/r/105598
Comment 17 Sarika Sinha CLA 2017-09-22 05:04:58 EDT
(In reply to Eclipse Genie from comment #16)
> New Gerrit change created: https://git.eclipse.org/r/105598

We don't need to calculate Bootpath for Modular vms.
Comment 18 Sarika Sinha CLA 2017-09-22 05:05:56 EDT
(In reply to Jay Arthanareeswaran from comment #14)
> One question that I have: Why don't I see this in the last week's Y build?

https://git.eclipse.org/r/104302
Made the run configurations to use project's JRE which is 8 in your case.
Comment 19 Jay Arthanareeswaran CLA 2017-09-22 05:16:24 EDT
I can confirm both the patches (from Till and Sarika) fixes my scenario.
Comment 20 Sarika Sinha CLA 2017-09-22 05:25:09 EDT
Yes, so for many cases bootclasspath is not set and it will work so I will fix this with e mentioned change.
Created Bug 522633 for PDE changes to be done.
Comment 21 Sarika Sinha CLA 2017-09-22 06:21:46 EDT
Working on some tests which expect bootpath
Comment 22 Vikas Chandra CLA 2017-09-22 06:35:15 EDT
Bug 522633  works for me with org.eclipse.jdt.launching patch
Comment 23 Sasikanth Bharadwaj CLA 2017-09-22 06:53:38 EDT
Please check other java launch delegate based configurations like m2e as well with the patch. Right now, I cannot launch an m2e configuration even using a 1.8 jre
Comment 24 Eclipse Genie CLA 2017-09-22 07:37:29 EDT
Gerrit change https://git.eclipse.org/r/105598 was merged to [R4_7_maintenance].
Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=5dc3b41e97884a94e4037ca7ae78bc4a7c4d962c
Comment 25 Sarika Sinha CLA 2017-09-22 07:38:52 EDT
Noo getBootpath will return null for run configurations running on Java9 and above.

Changed the boothpath testcases to adapt to it.
Comment 26 Vikas Chandra CLA 2017-09-22 07:44:08 EDT
>>--add-modules=ALL-SYSTEM in vm arguments

Not on 4.7.1a builds

Thankfully this problem is fixed in later  4.7.1a builds. (eclipse.ini in later builds have this).
Comment 27 Dani Megert CLA 2017-09-22 08:51:06 EDT
(In reply to Vikas Chandra from comment #26)
> >>--add-modules=ALL-SYSTEM in vm arguments
> 
> Not on 4.7.1a builds
> 
> Thankfully this problem is fixed in later  4.7.1a builds. (eclipse.ini in
> later builds have this).

NOTE:
- this will currently not be there if you use an EPP
- it is there if you use recent I-builds
Comment 28 Jay Arthanareeswaran CLA 2017-09-22 09:05:43 EDT
(In reply to Sasikanth Bharadwaj from comment #23)
> Please check other java launch delegate based configurations like m2e as
> well with the patch. Right now, I cannot launch an m2e configuration even
> using a 1.8 jre

Will Sarika's fix this one too?
Comment 29 Sarika Sinha CLA 2017-09-25 02:31:20 EDT
(In reply to Jay Arthanareeswaran from comment #28)
> (In reply to Sasikanth Bharadwaj from comment #23)
> > Please check other java launch delegate based configurations like m2e as
> > well with the patch. Right now, I cannot launch an m2e configuration even
> > using a 1.8 jre
> 
> Will Sarika's fix this one too?

We are working on that, that's a separate issue all together
Bug 522333