Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368804 - switching branch throws exception in history view
Summary: switching branch throws exception in history view
Status: VERIFIED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 369418 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-01-17 05:02 EST by Markus Duft CLA
Modified: 2012-01-26 14:44 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Duft CLA 2012-01-17 05:02:29 EST
Build Identifier: 

i just switched branches on current nightly (1.3.0.201201162014) and i got this exception from the history view ("error while notifying a preference changed listener" or something like that was displayed).

org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.SWT.error(SWT.java:4168)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:404)
	at org.eclipse.swt.widgets.Table.deselectAll(Table.java:956)
	at org.eclipse.jface.viewers.TableViewer.doDeselectAll(TableViewer.java:277)
	at org.eclipse.jface.viewers.AbstractTableViewer.setSelectionToWidget(AbstractTableViewer.java:880)
	at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:1769)
	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1450)
	at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1404)
	at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1506)
	at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537)
	at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1465)
	at org.eclipse.egit.ui.internal.history.GitHistoryPage$1.propertyChange(GitHistoryPage.java:602)
	at org.eclipse.ui.preferences.ScopedPreferenceStore$3.run(ScopedPreferenceStore.java:375)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.preferences.ScopedPreferenceStore.firePropertyChangeEvent(ScopedPreferenceStore.java:372)
	at org.eclipse.ui.preferences.ScopedPreferenceStore$2.preferenceChange(ScopedPreferenceStore.java:194)
	at org.eclipse.core.internal.preferences.EclipsePreferences$2.run(EclipsePreferences.java:754)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.preferences.EclipsePreferences.firePreferenceEvent(EclipsePreferences.java:757)
	at org.eclipse.core.internal.preferences.EclipsePreferences.put(EclipsePreferences.java:770)
	at org.eclipse.ui.preferences.ScopedPreferenceStore.setValue(ScopedPreferenceStore.java:789)
	at org.eclipse.egit.ui.internal.branch.BranchProjectTracker.save(BranchProjectTracker.java:163)
	at org.eclipse.egit.ui.internal.branch.BranchOperationUI$1$2.postExecute(BranchOperationUI.java:194)
	at org.eclipse.egit.core.op.BaseOperation.postExecute(BaseOperation.java:59)
	at org.eclipse.egit.core.op.BranchOperation$1.run(BranchOperation.java:117)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2326)
	at org.eclipse.egit.core.op.BranchOperation.execute(BranchOperation.java:123)
	at org.eclipse.egit.ui.internal.branch.BranchOperationUI$1.run(BranchOperationUI.java:199)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

Reproducible: Sometimes

Steps to Reproduce:
1. switch branches

it does not happen always... :(

i think there is a syncExec missing in the propertyChange handler in the GitHistoryPage... that should fix it.
Comment 1 Markus Duft CLA 2012-01-17 05:14:09 EST
proposed fix at http://egit.eclipse.org/r/#change,4967
Comment 2 Dani Megert CLA 2012-01-17 12:13:08 EST
> i think there is a syncExec missing in the propertyChange handler in the
> GitHistoryPage...

Nope, this is not needed. The wrong merge for bug 368526 causes the IAE.
Comment 3 Robin Rosenberg CLA 2012-01-17 17:41:32 EST
(In reply to comment #2)
> > i think there is a syncExec missing in the propertyChange handler in the
> > GitHistoryPage...
> 
> Nope, this is not needed. The wrong merge for bug 368526 causes the IAE.

That code should survive being called at any time, with a change in the
setting or not, so a (a)sycnexec is needed for that reason, if not for
your particular call sequence.
Comment 4 Robin Rosenberg CLA 2012-01-17 18:34:51 EST
Why is a change in the relative date setting, published?
Comment 5 Dani Megert CLA 2012-01-18 03:09:36 EST
(In reply to comment #4)
> Why is a change in the relative date setting, published?

It is not, that's the point. Here's how the old code looked like:

	if (UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(event
			.getProperty()))
		if (graph.setRelativeDate(((Boolean) event.getNewValue())
					.booleanValue()))
			graph.getTableView().refresh();

Yes, not easy readable without braces and with bad indentation. Basically, the refresh only happened if the event was for RESOURCEHISTORY_SHOW_RELATIVE_DATE property and only if the value changed.

You changed the code to *always* call refresh() no matter what the property is:

	if (UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(event
			.getProperty()))
		graph.setRelativeDate(isShowingRelativeDates());
		graph.getTableView().refresh();


The latest suggested patch at least only updates when the property matches but it sill updates when the value remains the same. Also, the relative date setting is a UI property that gets changed via UI preference (in the UI thread). Hence that code always worked in the past. Adding a (a)syncExec is not needed.

The correct code should be as indicated in my very first patch:

	if (UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(event
			.getProperty()))
		if (graph.setRelativeDate(isShowingRelativeDates()))
			graph.getTableView().refresh();
	}
Comment 6 Markus Duft CLA 2012-01-18 03:29:38 EST
phew. is it absolutely unthinkable that such properties will be changed in the future from a background thread? i think of some "preference import job" or something like that... i'd still sleep better if an [a]syncExec would be there. at least a big fat // WARNING: should be there i think...
Comment 7 Dani Megert CLA 2012-01-18 03:30:10 EST
> if (graph.setRelativeDate(isShowingRelativeDates()))

OK, I see that this no longer works since the signature of setRelativeDate(...) got changed. I'll upload a new patch.
Comment 8 Dani Megert CLA 2012-01-18 03:44:52 EST
(In reply to comment #6)
> phew. is it absolutely unthinkable that such properties will be changed in the
> future from a background thread? i think of some "preference import job" or
> something like that... i'd still sleep better if an [a]syncExec would be there.
> at least a big fat // WARNING: should be there i think...

It's a bit a gray area but the general rule is that those *calling* UI code (which a property change listener is, since it comes from JFace) are responsible to only call it in the UI thread. That's why e.g. the preference import happens in the UI thread and not in a job. On the other hand, if one knows/expects that the code is called from any thread then an (a)syncExec makes sense.

I generally try to avoid polluting the code with (a)syncExec if possible. This is for two reasons:
1) It can cause deadlocks.
2) It can change the event flow/order and cause ugly things which are hard to debug.
Comment 9 Robin Rosenberg CLA 2012-01-18 12:32:51 EST
(In reply to comment #5)

> The correct code should be as indicated in my very first patch:
> 
>     if (UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(event
>             .getProperty()))
>         if (graph.setRelativeDate(isShowingRelativeDates()))
>             graph.getTableView().refresh();
>     }

Aaaaahh.. You're absolutely right.
Comment 10 Dani Megert CLA 2012-01-19 03:45:01 EST
The change got merged.
Comment 11 Dani Megert CLA 2012-01-19 03:45:17 EST
Verified in 1.3.0.201201181724.
Comment 12 Kevin Sawicki CLA 2012-01-26 14:44:14 EST
*** Bug 369418 has been marked as a duplicate of this bug. ***