Skip to content

Commit

Permalink
Fix APSTUD-7324 IllegalStateException setting Job's system property
Browse files Browse the repository at this point in the history
  - Add an EclipseUtil.setSystemForJob(Job) method
  - Wrap all calls to setSystem in a try/catch block that catches and ignores an IllegalStateException that may get thrown if the job is already scheduled/running (which may even happen for brand new instances of jobs because of processor branch predictions)
  • Loading branch information
sgtcoolguy committed Aug 27, 2012
1 parent 6216cc2 commit f834259
Show file tree
Hide file tree
Showing 58 changed files with 774 additions and 397 deletions.
Expand Up @@ -39,6 +39,7 @@

import com.aptana.core.logging.IdeLog;
import com.aptana.core.resources.IProjectContext;
import com.aptana.core.util.EclipseUtil;
import com.aptana.core.util.FileUtil;

/**
Expand Down Expand Up @@ -75,7 +76,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
workbenchJob.setSystem(true);
EclipseUtil.setSystemForJob(workbenchJob);
workbenchJob.setPriority(WorkbenchJob.INTERACTIVE);
workbenchJob.schedule();

Expand Down
Expand Up @@ -125,7 +125,7 @@ public void connectionPointChanged(ConnectionPointEvent event)
}

};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}

Expand Down
9 changes: 8 additions & 1 deletion plugins/com.aptana.core/src/com/aptana/core/CorePlugin.java
Expand Up @@ -76,7 +76,14 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(true);
try
{
job.setSystem(true);
}
catch (IllegalStateException e)
{
// ignore
}
job.schedule();
}

Expand Down
13 changes: 13 additions & 0 deletions plugins/com.aptana.core/src/com/aptana/core/util/EclipseUtil.java
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.InstanceScope;
Expand Down Expand Up @@ -364,6 +365,18 @@ public static boolean showSystemJobs()
ICorePreferenceConstants.PREF_SHOW_SYSTEM_JOBS, false, null);
}

public static void setSystemForJob(Job job)
{
try
{
job.setSystem(!showSystemJobs());
}
catch (IllegalStateException e)
{
// ignore
}
}

/**
* Set the debugging state of the platform
*/
Expand Down
Expand Up @@ -999,7 +999,7 @@ public void run()
return Status.OK_STATUS;
}
};
linkWithEditorJob.setSystem(true);
EclipseUtil.setSystemForJob(linkWithEditorJob);
linkWithEditorJob.schedule();
}
}
Expand Down
Expand Up @@ -324,7 +324,7 @@ public void preferenceChange(PreferenceChangeEvent event)
}
};

job.setSystem(true);
EclipseUtil.setSystemForJob(job);
job.schedule(2000);
}

Expand Down
Expand Up @@ -57,7 +57,7 @@ class FilenameDifferentiator extends UIJob implements IPartListener
public FilenameDifferentiator()
{
super("Install filename differentiator"); //$NON-NLS-1$
setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(this);
baseNames = new HashMap<String, Set<IEditorPart>>();
}

Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.ui.progress.WorkbenchJob;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

import com.aptana.core.util.EclipseUtil;
import com.aptana.core.util.StringUtil;
import com.aptana.editor.common.AbstractThemeableEditor;
import com.aptana.editor.common.CommonEditorPlugin;
Expand Down Expand Up @@ -294,7 +295,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
fFilterRefreshJob.setSystem(true);
EclipseUtil.setSystemForJob(fFilterRefreshJob);
}

public void refresh(IParseRootNode ast)
Expand Down
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

import com.aptana.core.logging.IdeLog;
import com.aptana.core.util.EclipseUtil;
import com.aptana.editor.common.AbstractThemeableEditor;
import com.aptana.editor.common.CommonEditorPlugin;
import com.aptana.parsing.ast.IParseNode;
Expand Down Expand Up @@ -206,11 +207,11 @@ else if (element instanceof IParseNode)

// create filter refresh job
this._filterRefreshJob = this.createRefreshJob();
this._filterRefreshJob.setSystem(true);
EclipseUtil.setSystemForJob(this._filterRefreshJob);

// create delayed update job
this._delayedRefreshJob = this.createDelayedRefreshJob();
this._delayedRefreshJob.setSystem(true);
EclipseUtil.setSystemForJob(this._delayedRefreshJob);

// create document change listener and add to editor
this.createDocumentListener();
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.eclipse.ui.texteditor.ITextEditor;

import com.aptana.core.logging.IdeLog;
import com.aptana.core.util.EclipseUtil;
import com.aptana.core.util.IOUtil;
import com.aptana.core.util.StringUtil;
import com.aptana.editor.common.CommonEditorPlugin;
Expand Down Expand Up @@ -883,7 +884,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
}
};
hideJob.setPriority(Job.INTERACTIVE);
hideJob.setSystem(true);
EclipseUtil.setSystemForJob(hideJob);
hideJob.schedule(DELAY);

shell.addShellListener(new ShellAdapter()
Expand Down
Expand Up @@ -91,14 +91,7 @@ private void bundleFileChanged(File script)
// basically only make us run once if we get hit multiple times in a row. We'll still probably run a few
// times, but this should cut it down a lot.
job.cancel();
try
{
job.setSystem(!EclipseUtil.showSystemJobs());
}
catch (IllegalStateException ise)
{
// ignore
}
EclipseUtil.setSystemForJob(job);
job.schedule(750);
}

Expand Down
Expand Up @@ -281,7 +281,7 @@ protected IStatus run(IProgressMonitor monitor)
}
};
job.setPriority(Job.DECORATE);
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
}
if (!delayedRegions.isEmpty())
{
Expand Down
Expand Up @@ -147,7 +147,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
uiJob.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(uiJob);
uiJob.schedule();
}

Expand Down
Expand Up @@ -553,7 +553,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
// We have to delay it a bit, otherwise, the tree collapse back due
// to other jobs.
job.schedule(getRefreshJobDelay() * 2);
Expand Down Expand Up @@ -712,7 +712,7 @@ protected void setFilter(IResource resource)
private void createRefreshJob()
{
refreshJob = doCreateRefreshJob();
refreshJob.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(refreshJob);
}

/**
Expand Down
Expand Up @@ -128,7 +128,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.setPriority(Job.SHORT);
job.schedule(300);
}
Expand Down Expand Up @@ -188,7 +188,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
pullCalc.setSystem(true);
EclipseUtil.setSystemForJob(pullCalc);
pullCalc.setPriority(Job.LONG);
pullCalc.schedule();
}
Expand Down Expand Up @@ -352,7 +352,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.setPriority(Job.INTERACTIVE);
job.schedule();
}
Expand Down Expand Up @@ -574,7 +574,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
}
}
};
refreshUIJob.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(refreshUIJob);
refreshUIJob.setPriority(Job.INTERACTIVE);
refreshUIJob.schedule(100);
}
Expand Down
Expand Up @@ -543,7 +543,7 @@ public IStatus runInUIThread(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(true);
EclipseUtil.setSystemForJob(job);
job.setPriority(Job.BUILD);
job.schedule(250);

Expand Down
Expand Up @@ -79,7 +79,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}

Expand Down
Expand Up @@ -60,7 +60,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}
Expand Down
Expand Up @@ -174,7 +174,7 @@ private GitAutoAttachProjectJob(String name, Set<IProject> projectsToAttach)
{
super(name);
this.projectsToAttach = projectsToAttach;
setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(this);
setPriority(Job.SHORT);
}

Expand Down
Expand Up @@ -107,7 +107,7 @@ public boolean belongsTo(Object family)
return family == GitIndex.this;
}
};
indexRefreshJob.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(indexRefreshJob);
}
else
{
Expand Down Expand Up @@ -189,10 +189,9 @@ public String map(IPath location)
this.files = new Vector<ChangedFile>();

// Schedule all the jobs
boolean setSystem = !EclipseUtil.showSystemJobs();
for (Job toSchedule : jobs)
{
toSchedule.setSystem(setSystem);
EclipseUtil.setSystemForJob(toSchedule);
toSchedule.setPriority(Job.SHORT);
toSchedule.schedule();
}
Expand Down Expand Up @@ -753,7 +752,7 @@ public boolean belongsTo(Object family)
return family == GitIndex.this;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}

Expand Down
Expand Up @@ -336,7 +336,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}));
Expand Down Expand Up @@ -386,7 +386,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}
Expand Down Expand Up @@ -433,7 +433,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}

Expand Down Expand Up @@ -465,7 +465,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}));
Expand Down Expand Up @@ -506,7 +506,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}
Expand Down Expand Up @@ -538,7 +538,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}
Expand All @@ -563,7 +563,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}
Expand All @@ -586,7 +586,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.schedule();
}
}
Expand Down
Expand Up @@ -74,7 +74,7 @@ protected IStatus run(IProgressMonitor monitor) {
return Status.OK_STATUS;
}
};
job.setSystem(!EclipseUtil.showSystemJobs());
EclipseUtil.setSystemForJob(job);
job.setPriority(Job.LONG);
job.schedule();
}
Expand Down
Expand Up @@ -99,7 +99,7 @@ protected IStatus run(IProgressMonitor monitor)
return Status.OK_STATUS;
}
};
job.setSystem(true);
EclipseUtil.setSystemForJob(job);
job.schedule();
}

Expand Down

0 comments on commit f834259

Please sign in to comment.