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

Bug 155996

Summary: Old version of installed bundle gets loaded (was: LinkageError on TextEdit)
Product: [Eclipse Project] Equinox Reporter: Yaroslav Bulatov <yaroslavvb>
Component: FrameworkAssignee: Thomas Watson <tjwatson>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: daniel_megert, david_williams, jeffmcaffer, martinae, pombredanne, tjwatson, zhouyiy
Version: 3.3   
Target Milestone: 3.2.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 181382    
Attachments:
Description Flags
my configuration details
none
3.3 patch for the framework
none
3.2.x patch for the framework none

Description Yaroslav Bulatov CLA 2006-09-01 13:03:59 EDT
I get the following error when I do "Source/Format" on Java source. When I run Eclipse 3.2 with the same settings and plugins on the same file, I get no such error.

java.lang.LinkageError: loader constraints violated when linking org/eclipse/text/edits/TextEdit class
	at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format2(CodeFormatterUtil.java:229)
	at org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy.format(JavaFormattingStrategy.java:64)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:192)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:134)
	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:822)
	at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1519)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperation(JavaSourceViewer.java:178)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:200)
	at org.eclipse.ui.texteditor.TextOperationAction$1.run(TextOperationAction.java:131)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:129)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:499)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:461)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:424)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:160)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:466)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:799)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:846)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:564)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:506)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:122)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:982)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:927)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:952)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:937)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:965)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:961)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1275)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3352)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3252)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4054)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1928)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2995)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
	at org.eclipse.jface.window.Window.open(Window.java:796)
	at org.eclipse.pde.internal.runtime.logview.EventDetailsDialog.open(EventDetailsDialog.java:183)
	at org.eclipse.pde.internal.runtime.logview.EventDetailsDialogAction.run(EventDetailsDialogAction.java:91)
	at org.eclipse.pde.internal.runtime.logview.LogView$13.doubleClick(LogView.java:403)
	at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:796)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.runtime.Platform.run(Platform.java:843)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:149)
	at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:794)
	at org.eclipse.jface.viewers.AbstractTreeViewer.handleDoubleSelect(AbstractTreeViewer.java:1227)
	at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:1158)
	at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:223)
	at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:220)
	at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:281)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3377)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2997)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
	at org.eclipse.core.launcher.Main.run(Main.java:977)
	at org.eclipse.core.launcher.Main.main(Main.java:952)
Comment 1 Olivier Thomann CLA 2006-09-05 12:45:04 EDT
Could you please provide a test case and the build id?
Thanks.
Comment 2 Yaroslav Bulatov CLA 2006-09-05 15:50:17 EDT
Build id: I20060810-1230


Test case:

Create new Java Project, create new class Test, type the following
public interface Test { }, go to Source/Format

Comment 3 Olivier Thomann CLA 2006-09-05 21:57:47 EDT
Closing as dup of bug 155981.
If you didn't install on top of an existing installation, please reopen.

*** This bug has been marked as a duplicate of 155981 ***
Comment 4 Martin Aeschlimann CLA 2006-09-06 06:27:19 EDT
Hm, a duplicate, let's have a closer look:
When you installed over the old version, did you extract the whole JAR or just a selection of plugins (e.g. on JDT)?
Do you have other plugins installed?

Do you still have the old install? Can start it again and attach here what you get from 'Help > About Eclipse SDK > Configuration Details'?

I tried to reproduce and extracted 3.3 M1 over 3.2 and then I20060830-1650 over that. Created a file and did organize import or format but didn't see a problem.

Me and Dani were wondering if it is possible that an older version of org.eclipse.text could be loaded. The configuration details show a strange state: all 3 instanceof of org.eclipse.text are markes as resolved, but non active. Jeff, do you have any idea what be the problem here? TestEdit didn't have any API change, but private methods got added. A subclass of TextEdits got a 'toString' added.
Comment 5 Martin Aeschlimann CLA 2006-09-06 06:28:04 EDT
Moving to core.runtime for comments
Comment 6 Martin Aeschlimann CLA 2006-09-06 06:29:49 EDT
*** Bug 155981 has been marked as a duplicate of this bug. ***
Comment 7 Dani Megert CLA 2006-09-06 06:31:12 EDT
> but non active
This might be because org.eclipse.text does not have an activator. However, I'd then expect two listed as 'installed' and one as 'resolved'.
Comment 8 Martin Aeschlimann CLA 2006-09-06 06:32:11 EDT
See also bug 155981 for more information
Comment 9 Martin Aeschlimann CLA 2006-09-06 06:34:14 EDT
Created attachment 49476 [details]
my configuration details

My configuration details, but as mentioned, I couldn't reproduce this bug. But the scenario is the same as in bug 155981
Comment 10 Dani Megert CLA 2006-09-06 06:35:37 EDT
I also tried this:
1. have R3.2
2. replace (i.e. delete old version) org.eclipse.text with latest 3.3 plug-in
==> no problems i.e. organize import and format work as expected.
Comment 11 Thomas Watson CLA 2006-09-06 09:31:04 EDT
The following bundles:

org.eclipse.jface (3.2.0.I20060605-1400) "JFace" [Resolved]
org.eclipse.jface (3.3.0.I20060801-0800) "JFace" [Resolved]
org.eclipse.jface (3.3.0.I20060829-0800) "JFace" [Resolved]
org.eclipse.jface.databinding (1.0.0.I20060605-1400) "JFace Data Binding" [Resolved]
org.eclipse.jface.databinding (1.0.100.I20060803-0010) "JFace Data Binding" [Resolved]
org.eclipse.jface.databinding (1.0.100.I20060829-0800) "JFace Data Binding" [Resolved]
org.eclipse.jface.text (3.2.0.v20060605-1400) "JFace Text" [Resolved]
org.eclipse.jface.text (3.3.0.v20060809-1200) "JFace Text" [Resolved]
org.eclipse.jface.text (3.3.0.v20060829-0800) "JFace Text" [Resolved]
org.eclipse.text (3.2.0.v20060605-1400) "Text" [Resolved]
org.eclipse.text (3.3.0.v20060809-1200) "Text" [Resolved]
org.eclipse.text (3.3.0.v20060829-0800) "Text" [Resolved]

Are not specified as singleton bundles.  This allows more than one version to be resolved at the same time.  Are there issues if multiple versions of jface and text are used in the same system?  Should these bundles be specified as singleton bundles?
Comment 12 Dani Megert CLA 2006-09-06 09:34:19 EDT
>Are not specified as singleton bundles
Can't tell for sure but I think someone ones said this is only needed if there's an activator.
Comment 13 Thomas Watson CLA 2006-09-06 09:48:58 EDT
This is not really a reason to use singletons.  Here are the most common reasons:

- The bundle specifies extensions or extension points.  The extension registry require these bundles to be singletons
- The bundle uses a resource that cannot be shared between different versions of the bundle.  SWT declares itself a singleton because it does not want to share the display with other versions of SWT.

This does not really have anything to do with whether you have a bundle activator or not.  Non-singleton bundles are allowed to have bundle activators.

What I expect is happening here is that different bundles are getting wired to different versions of jface and when they attempt to pass objects between to two clients things start to break.
Comment 14 Dani Megert CLA 2006-09-06 09:53:24 EDT
Yes, I can also remember all those other arguments but they don't apply to org.eclipse.text i.e. I would still mark it as no-singleton when following those rules.
Comment 15 Dani Megert CLA 2006-09-07 02:32:16 EDT
Jeff,

this sounds more serious to me. Might this be a 3.2.1 candidate?
Comment 16 Dani Megert CLA 2006-09-28 12:00:32 EDT
I'm increasing the severity of this one, because it affects all clients where new versions of a bundle get installed into the same location as existing ones.

I just run into a similar problem - no linkage error BUT it seems that Equinox loads classes from BOTH VERSIONS of the installed plug-ins. I have the following installed:
  org.eclipse.jface.text_3.3.0.v20060926-0800.jar
      Bundle-Version: 3.3.0.v20060926-0800
  org.eclipse.jface.text_3.3.0.zzz20060927-1520.jar
      Bundle-Version: 3.3.0.zzz20060927-1520

and both got RESOLVED. I would expect that only the newest gets resolved.

This happens because singleton:=true isn't specified which in my opinion should not cause the effect that an older bundle versions gets used.
Comment 17 Thomas Watson CLA 2006-09-28 13:39:02 EDT
If a bundle is not a singleton bundle then it is "by design" that each bundle is allowed to resolve.  And both can be used by different clients.  If you want to prevent that then you should specify them as singletons.
Comment 18 BJ Hargrave CLA 2006-09-28 14:19:24 EDT
(In reply to comment #16)

> This happens because singleton:=true isn't specified which in my opinion should
> not cause the effect that an older bundle versions gets used.
> 

It is a key feature of OSGi to allow multiple versions of classes to be loaded if desired. This allows clients which require different versions of some class to run  in the same framework. If you don't want to allow this for your bundle, either don't install multiple versions of the bundle, or have all the versions of the bundle marked as singletons.
Comment 19 Dani Megert CLA 2006-10-09 05:55:04 EDT
I see this but shouldn't it always take the "newest" one that matches the client's requirement? Why does it load two different versions if the newest works for both clients? Or in other words: what is the algorithm to decide which version of the plug-in to load?
Comment 20 Kris Zyp CLA 2006-10-10 15:37:53 EDT
Is there any work around for this bug until a new release fixes.  I am using eclipse and this bug in this last release is a major problem for using eclipse.  What can I do?
Comment 21 Kris Zyp CLA 2006-10-10 15:41:47 EDT
Nevermind, I figured out, I just delete my old org.eclipse.text_3.1.1.jar.

Comment 22 Dani Megert CLA 2006-10-11 04:08:15 EDT
Can an equinox runtime expert comment on comment 19 i.e. is it really the case that if more than one version of a (non-singleton) bundle meets the version requirement an arbitrary version is taken each time and that this process is not deterministic?
Comment 23 Thomas Watson CLA 2006-10-11 15:57:26 EDT
(In reply to comment #19 and comment #20)

It depends on a few things ...

The framework does not agressively rewire previously resolved bundles to new bundles when they get installed.  So if some clients are wired to the old version of your bundle and a new version of your bundle is installed along with a set of other bundles that use your new bundle then some of the bundles in the framework will be wired to your old version and other newly installed/resolved bundles will get wired to the new version of your bundle.  The only way the bundles wired to your old bundle will get wired to the new bundle is by forcing them to refresh.

Is there a reason both versions are installed?  It seems like core.update should have uninstalled your old version so the other bundles are forced to re-resolve to use the newer version of your bundle.  Is this really a valid configuration?  If so then core.update needs to be smarter to make sure everyone starts using the highest versions possible.  This would involve them selectively refreshing bundles wired to older versions of the bundle.  

But this lead me to ask ... why do you want older versions of your bunlde installed if you do not want anyone to actually be wired to them?

Comment 24 Dani Megert CLA 2006-10-12 04:44:21 EDT
Just to clarify: does your comment only apply to a single run or is there a cache and subsequent runs are affected as well? Or in other words: if the workbench is restarted then the problem is gone (or not)?

>The only way the
>bundles wired to your old bundle will get wired to the new bundle is by forcing
>them to refresh.
How can I do that?

I guess another thing we should do is mark the plug-ins as singletons, right?
Comment 25 Thomas Watson CLA 2006-10-12 08:54:57 EDT
(In reply to comment #24)
> Just to clarify: does your comment only apply to a single run or is there a
> cache and subsequent runs are affected as well? Or in other words: if the
> workbench is restarted then the problem is gone (or not)?

We cache the resolution state of the bundles so we do not have to reparse and reresolve the state of the bundle wirings each startup.  This is a must when loading a configuration with potentially 1000s of bundles.  The problem should go away if you run with -clean after installing the new versions of the bundle.  This would force the newest possible bundles to be picked for each wiring.

> >The only way the
> >bundles wired to your old bundle will get wired to the new bundle is by forcing
> >them to refresh.
> How can I do that?

This is something the management agent would need to do (core.update).  Unfortunately I'm not sure there is a one size fits all policy for selecting what bundles need refreshed.  Instead I would like to focus on whether this is a valid configuration.  To me it seems like core.update should have noticed that the old bundles are not really needed anymore and probably should have uninstalled them from the configuration.

> I guess another thing we should do is mark the plug-ins as singletons, right?

That is one possibility, but we need to answer the question of whether it is valid to have more than one version of the library bundles installed at a time.  If it is and you make them singleton then you will prevent more than one version from ever being used at the same time in a configuration.
Comment 26 Dani Megert CLA 2006-10-12 09:11:58 EDT
>If it is and you make them singleton then you will prevent more than one
>version from ever being used at the same time in a configuration.
Well, almost all source plug-ins in the Eclipse SDK are marked as singletons (according to Jeff at least those that populate the plug-in registry should be) hence making org.eclipse.text shouldn't change much, should it? Note that org.eclipse.text is a source plug-in and not encapsulating a library.
Comment 27 Dani Megert CLA 2006-10-17 06:03:08 EDT
Thomas, can you or some other equinox runtime expert please comment on comment 26. Thanks.
Comment 28 Dani Megert CLA 2006-10-25 11:15:09 EDT
ping.
Comment 29 Thomas Watson CLA 2006-10-25 11:51:57 EDT
I'm not sure what you mean by "source plug-in".

Changing org.eclipse.text to a singleton bundle should not effect too much other than preventing other org.eclipse.text bundles which are *also* singleton bundles from resolving.
Comment 30 Dani Megert CLA 2006-10-25 12:17:31 EDT
>I'm not sure what you mean by "source plug-in".
I meant plug-ins that not only wrap some (external) library but is written by us (eclipse).
Comment 31 Dani Megert CLA 2006-10-25 13:06:30 EDT
Unless we find a better resolution for this critical bug for 3.2.2 I'll add the singleton statement into those plug-ins that are under my control.
Comment 32 Thomas Watson CLA 2006-12-01 10:34:55 EST
Moving to update for comment.

I do not understand why more than one version of org.eclipse.text are being installed in this case.  I thought update would uninstall the old version of the bundles when a feature is updated.  Can some on the update team comment on what scenarios cause more than one version of a bundle to be installed?
Comment 33 Thomas Watson CLA 2007-01-05 17:55:43 EST
*** Bug 169593 has been marked as a duplicate of this bug. ***
Comment 34 Thomas Watson CLA 2007-01-05 18:13:37 EST
Created attachment 56499 [details]
3.3 patch for the framework

See Bug 169593 comment 1 option 3

This patch changes the framework to force all old bundles to be refreshed when newly installed versions (with the same symbolic name) are installed.  Before we only did this for singleton bundles.  This patch will do this for all bundles that are being refreshed by update.configurator when it installs new bundles.  This will force the old bundles to be refreshed which will then make all bundles depending on the old bundles to be refreshed in a transitive closure graph.  Then when the bundles are resolved we will resolve them to the highest possible version of the bundles.  This should help solve the issue by allowing all bundles to use the same version of the installed bundle.

This patch is for 3.3.  I will attach a separate patch for 3.2.x stream if we feel this fix is necessary for 3.2.2.
Comment 35 Thomas Watson CLA 2007-01-05 18:16:58 EST
Created attachment 56500 [details]
3.2.x patch for the framework

same fix for 3.2.x.
Comment 36 Jeff McAffer CLA 2007-01-05 19:46:34 EST
+1 for 3.2.2.  Just to clarify, this is a Framework change no?  Is there an Update bug at all in any of this?  if not, the bug should be moved.

Also, please be sure that there is a 3.2.2 bug for this.
Comment 37 Pascal Rapicault CLA 2007-01-07 23:17:41 EST
Patch reviewed, good to go.
Comment 38 Thomas Watson CLA 2007-01-08 08:52:04 EST
Moving to Equinox since we decided to fix this in the Framework for 3.2.2.
Comment 39 Thomas Watson CLA 2007-01-08 10:57:04 EST
Patch released to 3.2.2 and HEAD.
Comment 40 Thomas Watson CLA 2007-04-09 10:13:40 EDT
*** Bug 181382 has been marked as a duplicate of this bug. ***