Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 195834 - [quick assist] BadLocationException when pressing Delete quickly after Extract to local
Summary: [quick assist] BadLocationException when pressing Delete quickly after Extrac...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 249336 254765 257153 264093 264141 266099 278808 281841 284139 284242 288296 289204 290094 290124 (view as bug list)
Depends on: 312189
Blocks: 257510
  Show dependency tree
 
Reported: 2007-07-09 10:42 EDT by Benno Baumgartner CLA
Modified: 2010-08-19 06:04 EDT (History)
20 users (show)

See Also:


Attachments
Fix (2.19 KB, patch)
2009-09-28 19:09 EDT, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2007-07-09 10:42:45 EDT
N20070707-0010

This is somewhat hard to reproduce, seams to be a timing issue:
1. Go to org.eclipse.jdt.internal.ui.fix.CleanUpSaveParticipantConfigurationModifyDialog.createDialogArea(Composite)
rev 1.4
2. Select composite.getFont()
3. Ctrl-1
4. Select 'Extract to local variable' and while the operation runs press 'Del'
Is:
 org.eclipse.core.runtime.CoreException[4]: org.eclipse.jface.text.BadLocationException: First position: 'font' at 4592, this position: ');
' at 4641
        at org.eclipse.jface.text.link.LinkedPositionGroup.enforceEqualContent(LinkedPositionGroup.java:130)
        at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:111)
        at org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal.enterLinkedMode(CUCorrectionProposal.java:348)
        at org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal.performChange(CUCorrectionProposal.java:313)
        at org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal.apply(CUCorrectionProposal.java:282)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:811)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:757)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1165)
        at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:788)
        at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:460)
        at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:60)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
        at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:706)
        at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5052)
        at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:4800)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
        at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:975)
        at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:971)
        at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1285)
        at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3772)
        at org.eclipse.swt.widgets.Control.windowProc(Control.java:3672)
        at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:291)
        at org.eclipse.swt.widgets.Display.windowProc(Display.java:4350)
        at org.eclipse.swt.internal.win32.OS.$$YJP$$DispatchMessageW(Native Method)
        at org.eclipse.swt.internal.win32.OS.DispatchMessageW(OS.java)
        at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2264)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3290)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
        at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
        at org.eclipse.core.launcher.Main.main(Main.java:30)

Now Undo works not correct anymore.
Comment 1 Markus Keller CLA 2007-07-09 13:48:07 EDT
I also could not reproduce in a runtime workbench, but it often happens when I try it in the host workbench. When I attached a debugger and halted in the BadLocationException, I saw that the document contained

		Font font= composite.getFont();
		fTabFolder.setFont();

..., i.e. the argument to setFont(Font) has already been deleted. It looks like the document has been changed some time after the refactoring changes have been applied (in ChangeCorrectionProposal.performChange(..)) and before we try to add linked positions.

From looking at the code, this can only happen if either the Delete key changes the document in another thread, or if the event loop is driven somewhere.
Comment 2 Markus Keller CLA 2007-07-09 13:59:39 EDT
Found the culprit by setting a breakpoint at the beginning of StyledText#handleKeyDown(Event) with this condition ...

int kc= event.keyCode;
System.out.println("keyCode: " + kc);
return kc == 120;

... and then quickly pressing the "x" key (not Delete) after selecting the quick fix with Enter. At this time, stdout ends with ...

keyCode: 13
keyCode: 120

... and the stack looks like the one below. The problem is that the EventLoopProgressMonitor runs the event loop after the change has been performed but before the linked mode is set up.

StyledText.handleKeyDown(Event) line: 5047	
StyledText$7.handleEvent(Event) line: 4800	
EventTable.sendEvent(Event) line: 66	
StyledText(Widget).sendEvent(Event) line: 938	
StyledText(Widget).sendEvent(int, Event, boolean) line: 962	
StyledText(Widget).sendEvent(int, Event) line: 947	
StyledText(Widget).sendKeyEvent(int, int, int, int, Event) line: 975	
StyledText(Widget).sendKeyEvent(int, int, int, int) line: 971	
StyledText(Widget).wmChar(int, int, int) line: 1285	
StyledText(Control).WM_CHAR(int, int) line: 3772	
StyledText(Control).windowProc(int, int, int, int) line: 3672	
StyledText(Canvas).windowProc(int, int, int, int) line: 291	
Display.windowProc(int, int, int, int) line: 4350	
OS.$$YJP$$DispatchMessageW(MSG) line: not available [native method]	
OS.DispatchMessageW(MSG) line: not available	
OS.DispatchMessage(MSG) line: 2264	
Display.readAndDispatch() line: 3290	
EventLoopProgressMonitor.runEventLoop() line: 123	
EventLoopProgressMonitor.isCanceled() line: 97	
ThreadJob.isCanceled(IProgressMonitor) line: 132	
ThreadJob.joinRun(IProgressMonitor) line: 167	
ImplicitJobs.begin(ISchedulingRule, IProgressMonitor, boolean) line: 87	
JobManager.beginRule(ISchedulingRule, IProgressMonitor) line: 225	
WorkManager.checkIn(ISchedulingRule, IProgressMonitor) line: 117	
Workspace.prepareOperation(ISchedulingRule, IProgressMonitor) line: 1744	
Workspace.checkpoint(boolean) line: 363	
UndoableOperation2ChangeAdapter.aboutToNotify(OperationHistoryEvent) line: 277	
TriggeredOperations.aboutToNotify(OperationHistoryEvent) line: 362	
DefaultOperationHistory$1.run() line: 911	
SafeRunner.run(ISafeRunnable) line: 37	
DefaultOperationHistory.notifyListeners(OperationHistoryEvent) line: 900	
DefaultOperationHistory.notifyDone(IUndoableOperation) line: 992	
DefaultOperationHistory.closeOperation(boolean, boolean, int) line: 1359	
UndoManager2.changePerformed(Change, boolean) line: 149	
QuickAssistProcessor$1(ChangeCorrectionProposal).performChange(IEditorPart, IDocument) line: 124	
QuickAssistProcessor$1(CUCorrectionProposal).performChange(IEditorPart, IDocument) line: 304	
QuickAssistProcessor$1(CUCorrectionProposal).apply(IDocument) line: 282	
CompletionProposalPopup.insertProposal(ICompletionProposal, char, int, int) line: 811	
CompletionProposalPopup.insertSelectedProposalWithMask(int) line: 757	
CompletionProposalPopup.verifyKey(VerifyEvent) line: 1165	
ContentAssistant$InternalListener.verifyKey(VerifyEvent) line: 788	
TextViewer$VerifyKeyListenersManager.verifyKey(VerifyEvent) line: 460	
StyledTextListener.handleEvent(Event) line: 60	
EventTable.sendEvent(Event) line: 66	
StyledText(Widget).sendEvent(Event) line: 938	
StyledText(Widget).sendEvent(int, Event, boolean) line: 962	
StyledText(Widget).sendEvent(int, Event) line: 947	
StyledText(Widget).notifyListeners(int, Event) line: 706	
StyledText.handleKeyDown(Event) line: 5052	
...
Comment 3 Markus Keller CLA 2007-07-10 04:32:33 EDT
I guess we should not get an EventLoopProgressMonitor any more when changes are executed in a non-UI thread, see bug 175733.
Comment 4 Markus Keller CLA 2008-10-06 05:09:50 EDT
*** Bug 249336 has been marked as a duplicate of this bug. ***
Comment 5 Markus Keller CLA 2008-11-10 12:31:18 EST
*** Bug 254765 has been marked as a duplicate of this bug. ***
Comment 6 Markus Keller CLA 2008-12-02 05:49:21 EST
*** Bug 257153 has been marked as a duplicate of this bug. ***
Comment 7 Markus Keller CLA 2008-12-05 12:19:53 EST
> I guess we should not get an EventLoopProgressMonitor any more when changes are
> executed in a non-UI thread, see bug 175733.

Unfortunately, this problem does not depend on bug 175733. The problem here (in the scenario from comment 2) is that UndoableOperation2ChangeAdapter#aboutToNotify(..) calls
    ResourcesPlugin.getWorkspace().checkpoint(false);
, which sometimes (unpredictably!) conflicts with the AutoBuildJob.

If that happens, ThreadJob#joinRun(..) drives the event loop via EventLoopProgressMonitor, which in turn allows the keystroke to modify the document between the execution of the change and the start of the linked proposal mode in CUCorrectionProposal#performChange(..).

I don't fully understand why we call IWorkspace#checkpoint(..) there. Furthermore, that method's Javadoc says "This method has no effect if invoked outside the dynamic scope of a call to the IWorkspace.run method.", but this is apparently not true, since the stack from comment 2 does not contain a frame Workspace.run(..).

Moving to M5 to decide whether we can just remove the calls to IWorkspace#checkpoint(..).

Another solution could be to check in ChangeCorrectionProposal#performChange(..) whether the change is just a TextChange, and if it is, avoid the refactoring undo manager and instead rely on the IRewriteTarget to collect the changes in one undo object.
Comment 8 Dani Megert CLA 2009-02-09 05:15:44 EST
*** Bug 264141 has been marked as a duplicate of this bug. ***
Comment 9 Dani Megert CLA 2009-02-09 05:15:49 EST
*** Bug 264093 has been marked as a duplicate of this bug. ***
Comment 10 Dani Megert CLA 2009-02-25 06:15:26 EST
*** Bug 266099 has been marked as a duplicate of this bug. ***
Comment 11 Markus Keller CLA 2009-04-30 13:06:43 EDT
I'll try to look at this again in RC1, otherwise 3.6.
Comment 12 Stephan Herrmann CLA 2009-05-27 14:14:41 EDT
Another way to reproduceable see the same exception:
Quickfix on unresolved message send to create a method in a class 
other than the current class.
Doesn't involve any intermediate editing.
The problem does _not_ occur when the preview of the quick fix
has been shown.
Could this be a racing between switching to the other editor
and computing the change?
Comment 13 Dani Megert CLA 2009-06-02 12:01:03 EDT
*** Bug 278808 has been marked as a duplicate of this bug. ***
Comment 14 Will Horn CLA 2009-06-06 16:07:36 EDT
I experienced this on 3.5RC3.  I created the following code:

public final class DiagnosticianContraint extends AbstractModelConstraint {

    public DiagnosticianContraint() {
    }

    @Override
    public IStatus validate(IValidationContext ctx) {
        Diagnostic d = Diagnostician.INSTANCE.validate(ctx.getTarget());
        return diagnosticToStatus(d);
    }
}

Then did a quick fix to generate the diagnosticToStatus stub.  Same exception as described, "org.eclipse.jface.text.BadLocationException: First position: '' at 622, this position: 'private' at 630".  I can't reproduce it.
Comment 15 Stephan Herrmann CLA 2009-06-09 18:21:37 EDT
Seeing the target milestone set to 3.6M1 I wonder
whether the number of dupes could be reason enough
to actually schedule this issue for 3.5.1?

I personally have been bitten by this bug in various situations lately,
which means that the desired assist doesn't complete,
which looks like a relevant regression to me.

Just my 2c.
Comment 16 Dani Megert CLA 2009-06-10 03:11:54 EDT
The bug is ugly but definitely not critical, however, if the fix turns out to be small and low risk we can consider for 3.5.1.
Comment 17 Dani Megert CLA 2009-06-29 11:08:01 EDT
*** Bug 281841 has been marked as a duplicate of this bug. ***
Comment 18 Remy Suen CLA 2009-07-16 05:50:34 EDT
I got this just now while using quick fix to cast an IContributionItem to a CommandContributionItem like so...

if (items[i] instanceof CommandContributionItem) {
  items[i].getCommand(); // invoked quick fix here
}

org.eclipse.core.runtime.CoreException: First position: '' at 4302, this position: 'CommandContributionItem' at 4304
        at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.performChange(CUCorrectionProposal.java:343)
        at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.apply(CUCorrectionProposal.java:301)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:931)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:877)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1304)
        at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:806)
        at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:489)
        at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:62)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
        at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1025)
        at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5837)
        at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5541)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
        at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1212)
        at org.eclipse.swt.widgets.Widget.gtk_key_press_event(Widget.java:706)
        at org.eclipse.swt.widgets.Control.gtk_key_press_event(Control.java:2837)
        at org.eclipse.swt.widgets.Composite.gtk_key_press_event(Composite.java:703)
        at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1570)
        at org.eclipse.swt.widgets.Control.windowProc(Control.java:4586)
        at org.eclipse.swt.widgets.Display.windowProc(Display.java:4191)
        at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
        at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:7586)
        at org.eclipse.swt.widgets.Display.eventProc(Display.java:1185)
        at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
        at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1858)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3110)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Caused by: org.eclipse.jface.text.BadLocationException: First position: '' at 4302, this position: 'CommandContributionItem' at 4304
        at org.eclipse.jface.text.link.LinkedPositionGroup.enforceEqualContent(LinkedPositionGroup.java:132)
        at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:113)
        at org.eclipse.jdt.internal.ui.viewsupport.LinkedProposalModelPresenter.enterLinkedMode(LinkedProposalModelPresenter.java:94)
        at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.performChange(CUCorrectionProposal.java:332)
        ... 52 more
!SUBENTRY 1 org.eclipse.jdt.ui 4 4 2009-07-16 05:29:42.077
!MESSAGE First position: '' at 4302, this position: 'CommandContributionItem' at 4304
!STACK 0
org.eclipse.jface.text.BadLocationException: First position: '' at 4302, this position: 'CommandContributionItem' at 4304
        at org.eclipse.jface.text.link.LinkedPositionGroup.enforceEqualContent(LinkedPositionGroup.java:132)
        at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:113)
        at org.eclipse.jdt.internal.ui.viewsupport.LinkedProposalModelPresenter.enterLinkedMode(LinkedProposalModelPresenter.java:94)
        at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.performChange(CUCorrectionProposal.java:332)
        at org.eclipse.jdt.internal.ui.text.correction.proposals.CUCorrectionProposal.apply(CUCorrectionProposal.java:301)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:931)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:877)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1304)
        at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:806)
        at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:489)
        at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:62)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
Comment 19 Markus Keller CLA 2009-07-27 10:21:16 EDT
*** Bug 284242 has been marked as a duplicate of this bug. ***
Comment 20 Markus Keller CLA 2009-07-28 14:01:16 EDT
*** Bug 284139 has been marked as a duplicate of this bug. ***
Comment 21 Dani Megert CLA 2009-09-02 03:40:56 EDT
*** Bug 288296 has been marked as a duplicate of this bug. ***
Comment 22 Markus Keller CLA 2009-09-11 09:36:40 EDT
*** Bug 289204 has been marked as a duplicate of this bug. ***
Comment 23 Markus Keller CLA 2009-09-14 13:57:32 EDT
Sorry for shifting this again -- I was just running out of time. The fix will probably be to temporarily set the focus out of the StyledText, such that additional key event are not delivered to the text area any more (and thus cannot interfere with document modifications).
Comment 24 Markus Keller CLA 2009-09-28 13:00:07 EDT
*** Bug 290094 has been marked as a duplicate of this bug. ***
Comment 25 Markus Keller CLA 2009-09-28 13:00:54 EDT
*** Bug 290124 has been marked as a duplicate of this bug. ***
Comment 26 Markus Keller CLA 2009-09-28 19:09:18 EDT
Created attachment 148285 [details]
Fix

Prevents these problems on WinXP and GTK. Does not yet improve the situation on Cocoa, see bug 290759.

I could reproduce most of the time by starting a long build (e.g. clean and rebuild org.eclipse.jdt.ui), then using 'Ctrl+1, Enter' to start the 'Extract Local Variable' quick assist, and then quickly typing more keys before the 'blocked' dialog appears.
Comment 27 Markus Keller CLA 2009-09-28 19:10:15 EDT
Released to HEAD.
Comment 28 Markus Keller CLA 2009-09-29 08:59:20 EDT
I got the BadLocationException even with the initial fix. Digging deeper, I found that we actually have 2 different scenarios that both lead to a similar exception but have fundamentally different causes:

a) Quickly after applying the quick fix, the user types a key that gets processed too early by the EventLoopProgressMonitor (analysis in comment 7; can completely screw the document since TextEdits are applied to a modified document).

b) The user applies the quick fix at exactly the time when the additional proposal info (preview) gets computed. This leads to a race condition in ChangeCorrectionProposal#getChange().

Steps:

- have this CU:
package test;
public class Main {
	public static void main(String[] args) {
		bla(1); //caret on this line
	}
}

- set a breakpoint in ChangeCorrectionProposal#getChange() on the line "fChange= createChange();"
- press Ctrl+1
- wait 1 second
- press Enter
- resume the Worker thread
- resume the suspended Main thread

=> The main problem is that both threads use CUCorrectionProposal#getLinkedProposalModel() to add linked positions, but only the tracked AST nodes from the "winning" thread have their positions updated.

Scenario b) is probably what most dups of this bug were really about. I'll add a fix for that shortly.
Comment 29 Markus Keller CLA 2009-09-29 09:44:18 EDT
Released improved fix for a) and fix for b) to HEAD.
Filed bug 290805 for backporting b) to 3.5.2.
Comment 30 Markus Keller CLA 2010-05-09 16:17:51 EDT
This fix lead to deadlocks under GTK due to the SWT bug 293995. The fix has been reverted for GTK in 3.6 M7. Other platforms are not affected.

Opened bug 312189 for another fix for GTK.
Comment 31 Markus Keller CLA 2010-08-19 06:04:46 EDT
(In reply to comment #30)
> This fix lead to deadlocks under GTK due to the SWT bug 293995. The fix has
> been reverted for GTK in 3.6 M7. Other platforms are not affected.
> 
> Opened bug 312189 for another fix for GTK.

I've released a GTK fix for this to HEAD, which will be available in builds > N20100818-2000. We're considering backporting this to 3.6.1, but unfortunately, the patch didn't get much testing so far.

If people working on GTK test the fix and report their findings in bug 312189, that will increase the probability for this fix to appear in 3.6.1.