Bug 164643 - TextSearchVisitor.search(..) notifies progress monitor in wrong thread
Summary: TextSearchVisitor.search(..) notifies progress monitor in wrong thread
Status: CLOSED DUPLICATE of bug 561416
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Search (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.16 M3   Edit
Assignee: Platform-Search-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 451408 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-11-15 09:16 EST by Markus Keller CLA
Modified: 2020-04-20 16:10 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2006-11-15 09:16:07 EST
I20061114-1636

TextSearchVisitor.search(IFile[], IProgressMonitor) creates a new Job and notifies the progress monitor in another thread. This causes problems when the progress monitor expects to be called in the UI Thread.

E.g. when I rename a type with the "rename in editor" feature and enable "Update fully qualified names in non-java files", I get an error dialog and the exception below. The problem is that RenameLinkedMode.doRename(..) starts the refactoring with the workbench window as context and the StatusLine apparently cannot handle progress updates from other threads.


!ENTRY org.eclipse.core.jobs 4 2 2006-11-15 14:59:05.061
!MESSAGE An internal error occurred during: "Search progress polling".
!STACK 0
org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:3407)
	at org.eclipse.swt.SWT.error(SWT.java:3330)
	at org.eclipse.swt.SWT.error(SWT.java:3301)
	at org.eclipse.swt.widgets.Display.error(Display.java:1001)
	at org.eclipse.swt.widgets.Display.checkDevice(Display.java:661)
	at org.eclipse.swt.widgets.Display.getSystemColor(Display.java:1991)
	at org.eclipse.jface.action.StatusLine.updateMessageLabel(StatusLine.java:640)
	at org.eclipse.jface.action.StatusLine.setMessage(StatusLine.java:530)
	at org.eclipse.jface.action.StatusLine.setMessage(StatusLine.java:518)
	at org.eclipse.jface.action.StatusLine.subTask(StatusLine.java:599)
	at org.eclipse.jface.action.StatusLineManager$1.subTask(StatusLineManager.java:207)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:156)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:170)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:156)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:170)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:156)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:170)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:156)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:170)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:156)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:170)
	at org.eclipse.search.internal.core.text.TextSearchVisitor$1.run(TextSearchVisitor.java:148)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 1 Markus Keller CLA 2006-11-15 09:36:38 EST
The job has been introduced to fix bug 86963. I think to only way to solve both problems would be to invert the usage of the two threads, i.e. use the calling thread for progress notifications and do the actual search in the job.
Comment 2 Martin Aeschlimann CLA 2006-11-15 09:41:32 EST
- I don't think one is forced to serve a progress monitor in the same thread. At least this isn't specified by the progress monitor
- In your case, why do you execute the search operation in the UI thread? That's something that should be avoided in general
Comment 3 Markus Keller CLA 2006-11-15 10:33:20 EST
> - I don't think one is forced to serve a progress monitor in the same thread.
> At least this isn't specified by the progress monitor

Hard to tell, the section "The workbench and threads" in http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/swt_threading.htm says that in general, Platform/UI APIs assume they're called in the UI thread unless noted otherwise.

> - In your case, why do you execute the search operation in the UI thread?
> That's something that should be avoided in general

I'm investigating; I guess I can indeed set fork=true in my use case, which would solve this particular problem.
Comment 4 Martin Aeschlimann CLA 2006-11-15 12:17:55 EST
IProgressMonitor is org.eclipse.core.runtime. Operations are typically implemented in core which doesn't know of the concept of the UI thread.

I think we could also file this against platform UI. They normally already have progress monitors that forward calls with sync exec.
Comment 5 Markus Keller CLA 2006-11-15 18:19:05 EST
> I think we could also file this against platform UI. They normally already have
> progress monitors that forward calls with sync exec.

Hm, they already do, but it's not possible in this case: In ModalContext.run(..), if fork is false, the operation must be run in the current thread (which is the UI thread in our case). If they would wrapper the progress monitor into an AccumulatingProgressMonitor, then updates would only occur in an asyncExec, which is only executed when the whole refactoring operation returns (i.e. progress bar is not redrawn at all...).
Comment 6 Martin Oberhuber CLA 2011-07-26 11:21:47 EDT
Just ran into the same issue with our product (based on Eclipse 3.7 / indigo). 

I was testing search-and-replace on files out of sync wrt the file system, with the new "Refresh on Access" Preference on.
Comment 7 Dani Megert CLA 2014-11-17 07:48:57 EST
*** Bug 451408 has been marked as a duplicate of this bug. ***
Comment 8 Stephan Herrmann CLA 2015-10-04 09:59:18 EDT
AERI led me here after it happened in Mars.1.
Comment 9 Stephan Wahlbrink CLA 2020-04-20 11:52:53 EDT
The error still occurs in 2020-03:

eclipse.buildId=4.15.0.I20200305-0155
java.version=11.0.4
java.vendor=AdoptOpenJDK

org.eclipse.core.jobs
Error
Mon Apr 20 17:35:19 CEST 2020
An internal error occurred during: "Search progress polling".

org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:4723)
	at org.eclipse.swt.SWT.error(SWT.java:4638)
	at org.eclipse.swt.SWT.error(SWT.java:4609)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:432)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:352)
	at org.eclipse.swt.widgets.Control.getForeground(Control.java:1366)
	at org.eclipse.jface.action.StatusLine.updateMessageLabel(StatusLine.java:681)
	at org.eclipse.jface.action.StatusLine.setMessage(StatusLine.java:559)
	at org.eclipse.jface.action.StatusLine.setMessage(StatusLine.java:545)
	at org.eclipse.jface.action.StatusLine.subTask(StatusLine.java:641)
	at org.eclipse.jface.action.StatusLineManager$1.subTask(StatusLineManager.java:192)
	at org.eclipse.core.runtime.SubMonitor$RootInfo.subTask(SubMonitor.java:255)
	at org.eclipse.core.runtime.SubMonitor.subTask(SubMonitor.java:667)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:168)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:197)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:168)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:197)
	at org.eclipse.core.runtime.ProgressMonitorWrapper.subTask(ProgressMonitorWrapper.java:168)
	at org.eclipse.core.runtime.SubProgressMonitor.subTask(SubProgressMonitor.java:197)
	at org.eclipse.search.internal.core.text.TextSearchVisitor$1.run(TextSearchVisitor.java:364)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Comment 10 Karsten Thoms CLA 2020-04-20 16:10:07 EDT
This has been finally solved for 4.16

*** This bug has been marked as a duplicate of bug 561416 ***