EclipseVersionDetector fails, when starting Oxygen from the Eclipse IDE

Having trouble installing Oxygen? Got a bug to report? Post it all here.
SNO
Posts: 51
Joined: Mon Oct 01, 2012 3:05 pm

EclipseVersionDetector fails, when starting Oxygen from the Eclipse IDE

Post by SNO »

Hi,

I get the following exception when I try to open an Oxygen XML Editor instance in my Eclipse 4 RCP application, when I start it from the IDE:

Code: Select all

java.lang.NullPointerException
at java.util.StringTokenizer.<init>(StringTokenizer.java:199)
at java.util.StringTokenizer.<init>(StringTokenizer.java:221)
at ro.sync.basic.util.EclipseVersionDetector.getEclipseMajorVersion(EclipseVersionDetector.java:144)
at ro.sync.ui.hidpi.b.<init>(Unknown Source)
at ro.sync.ui.hidpi.RetinaDetector.getInstance(Unknown Source)
at com.oxygenxml.editor.swtutil.SmartScrollableCanvas.<init>(Unknown Source)
at com.oxygenxml.editor.swtutil.SmartScrollableCanvas.<init>(Unknown Source)
at com.oxygenxml.editor.editors.xsd.b.e.<init>(Unknown Source)
at com.oxygenxml.editor.editors.n.b.<init>(Unknown Source)
at com.oxygenxml.editor.editors.n.c.<init>(Unknown Source)
at com.oxygenxml.editor.editors.xml.AbstractXMLEditor.createEditorPages(Unknown Source)
at com.oxygenxml.editor.editors.q.createPages(Unknown Source)
at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:348)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:153)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1005)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:970)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:137)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:412)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:331)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:190)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:1012)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:672)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:778)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:749)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:743)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:727)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$1.handleEvent(PartServiceImpl.java:104)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4567)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:196)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
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.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:174)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:634)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:598)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:788)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1235)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3277)
at org.eclipse.ui.internal.WorkbenchPage.access$26(WorkbenchPage.java:3192)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3174)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:71)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3169)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3133)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3123)
at de.kgucms.tps.client.ide.openeditor.OpenEditorServiceImpl.openIdeEditor(OpenEditorServiceImpl.java:47)
at de.kgucms.tps.client.oxygen.handler.OpenOxygenEditorHandler.execute(OpenOxygenEditorHandler.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:318)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:252)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:161)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:204)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:433)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.handleWidgetSelection(AbstractContributionItem.java:446)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.lambda$2(AbstractContributionItem.java:472)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4118)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3931)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3534)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1170)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1059)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:667)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:597)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at de.kgucms.tps.client.app.Application.start(Application.java:49)
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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
at org.eclipse.equinox.launcher.Main.run(Main.java:1498)
at org.eclipse.equinox.launcher.Main.main(Main.java:1471)
Could you please provide a fallback for the EclipseVersionDetector class, which tries to read a system property in case the current way of obtaining the eclipse version does not work?

For example:

Code: Select all


System.getProperty("oxygenxml.eclipseversion");
Or do you already have a fallback, which we can use in order to avoid this exception, when running the application from the IDE.

Regards, Stefan
Stefan Nöbauer
Senior Solution Architect
KGU-Consulting GmbH
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: EclipseVersionDetector fails, when starting Oxygen from the Eclipse IDE

Post by Radu »

Hi Stefan,

The code we use to detect the Eclipse version (and which returns null in your case is something like):

Code: Select all

/**
* Find the Eclipse version from the "org.eclipse.platform_pluginVersionNumber" folder.
*
* @return The Eclipse version.
*/
public static String getEclipseVersion() {
// Get the old style version number, not valid for Eclipse after 3.7...
String version = System.getProperty("osgi.framework.version");
boolean tryWithPluginsDir = true;
try {
//EXM-29403 The easiest way to find out the Eclipse version.
Class platformClazz = Class.forName("org.eclipse.core.runtime.Platform");
Object defBundle = platformClazz.getMethod("getBundle", String.class).invoke(null, "org.eclipse.platform");
if (defBundle != null) {
Object platformVersionObj = defBundle.getClass().getMethod("getVersion", new Class[0]).invoke(defBundle);
if (platformVersionObj != null) {
String platformVersion = platformVersionObj.toString();
if (platformVersion != null && platformVersion.trim().length() > 0 && platformVersion.charAt(0) >= '4') {
version = platformVersion;
}
}
}
tryWithPluginsDir = false;
} catch(Exception t) {
//Should always work except if the Eclipse is verion 2.0 or lower.
logger.warn(t, t);
}
if (tryWithPluginsDir) {
// For versions after 4, the "org.eclipse.platform_pluginVersionNumber" is the corect one...
File f = new File(PlatformDetector.isMacOS() ? "./../../../plugins" : "./plugins");
File[] fs = f.listFiles(new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() && f.getName().startsWith("org.eclipse.platform_");
}
});
if (fs != null && fs.length >= 1 && fs[0] != null) {
List<String> platformVersions = new ArrayList<>();
for (int i = 0; i < fs.length; i++) {
String platformVersion = fs[i].getName().substring("org.eclipse.platform_".length());
if (platformVersion != null && platformVersion.trim().length() > 0 && platformVersion.charAt(0) >= '4') {
platformVersions.add(platformVersion);
}
}
if (!platformVersions.isEmpty()) {
Collections.sort(platformVersions);
version = platformVersions.get(platformVersions.size() - 1);
}
}
}
return version;
}
So if you manage to set the system property "osgi.framework.version" to a version value before our plugin is initialized, things should start working.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
SNO
Posts: 51
Joined: Mon Oct 01, 2012 3:05 pm

Re: EclipseVersionDetector fails, when starting Oxygen from the Eclipse IDE

Post by SNO »

Thanks very much.
Stefan Nöbauer
Senior Solution Architect
KGU-Consulting GmbH
Post Reply