Community
Participate
Working Groups
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.
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.
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 ...
I guess we should not get an EventLoopProgressMonitor any more when changes are executed in a non-UI thread, see bug 175733.
*** Bug 249336 has been marked as a duplicate of this bug. ***
*** Bug 254765 has been marked as a duplicate of this bug. ***
*** Bug 257153 has been marked as a duplicate of this bug. ***
> 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.
*** Bug 264141 has been marked as a duplicate of this bug. ***
*** Bug 264093 has been marked as a duplicate of this bug. ***
*** Bug 266099 has been marked as a duplicate of this bug. ***
I'll try to look at this again in RC1, otherwise 3.6.
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?
*** Bug 278808 has been marked as a duplicate of this bug. ***
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.
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.
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.
*** Bug 281841 has been marked as a duplicate of this bug. ***
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)
*** Bug 284242 has been marked as a duplicate of this bug. ***
*** Bug 284139 has been marked as a duplicate of this bug. ***
*** Bug 288296 has been marked as a duplicate of this bug. ***
*** Bug 289204 has been marked as a duplicate of this bug. ***
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).
*** Bug 290094 has been marked as a duplicate of this bug. ***
*** Bug 290124 has been marked as a duplicate of this bug. ***
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.
Released to HEAD.
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.
Released improved fix for a) and fix for b) to HEAD. Filed bug 290805 for backporting b) to 3.5.2.
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.
(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.