From 37c5d87fec223137a47818a76cc62dd8fdb39e48 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Thu, 11 May 2006 20:17:00 +0000 Subject: [PATCH] Improve robustness of the full and fast indexers. If Throwables are detected, the current file or name is skipped. This continues until a maximums is reached in which case the index job is aborted. --- .../pdom/indexer/fast/PDOMFastHandleDelta.java | 16 ++++++++++++++-- .../pdom/indexer/fast/PDOMFastIndexerJob.java | 16 ++++++++++------ .../core/pdom/indexer/fast/PDOMFastReindex.java | 12 ++++++++---- .../pdom/indexer/full/PDOMFullHandleDelta.java | 16 ++++++++++++++-- .../pdom/indexer/full/PDOMFullIndexerJob.java | 8 ++++++-- .../core/pdom/indexer/full/PDOMFullReindex.java | 10 +++++++--- 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java index a306854fb2c..adc588212e7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java @@ -60,7 +60,13 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { while (i.hasNext()) { ITranslationUnit tu = (ITranslationUnit)i.next(); monitor.subTask(tu.getElementName()); - changeTU(tu); + try { + changeTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + return Status.CANCEL_STATUS; + } monitor.worked(1); } @@ -68,7 +74,13 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { while (i.hasNext()) { ITranslationUnit tu = (ITranslationUnit)i.next(); monitor.subTask(tu.getElementName()); - addTU(tu); + try { + addTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + return Status.CANCEL_STATUS; + } monitor.worked(1); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java index 5ec60b6d529..cd395187738 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java @@ -39,6 +39,10 @@ public abstract class PDOMFastIndexerJob extends Job { protected final Map fileMap = new HashMap(); protected final PDOM pdom; + // Error counter. If we too many errors we bail + protected int errorCount; + protected final int MAX_ERRORS = 10; + public PDOMFastIndexerJob(PDOM pdom) { super("Fast Indexer: " + pdom.getProject().getElementName()); this.pdom = pdom; @@ -74,7 +78,7 @@ public abstract class PDOMFastIndexerJob extends Job { } finally { pdom.releaseWriteLock(); } - + // Tell the world pdom.fireChange(); } @@ -121,18 +125,18 @@ public abstract class PDOMFastIndexerJob extends Job { shouldVisitNames = true; shouldVisitDeclarations = true; } - public int visit(IASTName name) { + public int visit(IASTName name) { try { IASTFileLocation nameLoc = name.getFileLocation(); if (nameLoc != null) linkage.addName(name, getCachedFile(nameLoc.getFileName())); return PROCESS_CONTINUE; - } catch (CoreException e) { + } catch (Throwable e) { CCorePlugin.log(e); - return PROCESS_ABORT; + return ++errorCount > MAX_ERRORS ? PROCESS_ABORT : PROCESS_CONTINUE; } - }; - });; + } + }); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java index 3693900f06b..765565da475 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java @@ -72,8 +72,10 @@ public class PDOMFastReindex extends PDOMFastIndexerJob { monitor.subTask(tu.getElementName()); try { addTU(tu); - } catch (InterruptedException e) { - throw new CoreException(Status.CANCEL_STATUS); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + throw new CoreException(Status.CANCEL_STATUS); } monitor.worked(1); } @@ -101,8 +103,10 @@ public class PDOMFastReindex extends PDOMFastIndexerJob { monitor.subTask(tu.getElementName()); try { addTU(tu); - } catch (InterruptedException e) { - throw new CoreException(Status.CANCEL_STATUS); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + throw new CoreException(Status.CANCEL_STATUS); } } monitor.worked(1); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java index 18863e1e420..741451b1b7e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java @@ -70,7 +70,13 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob { while (i.hasNext()) { ITranslationUnit tu = (ITranslationUnit)i.next(); monitor.subTask(tu.getElementName()); - changeTU(tu); + try { + changeTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + return Status.CANCEL_STATUS; + } monitor.worked(1); } @@ -78,7 +84,13 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob { while (i.hasNext()) { ITranslationUnit tu = (ITranslationUnit)i.next(); monitor.subTask(tu.getElementName()); - addTU(tu); + try { + addTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + return Status.CANCEL_STATUS; + } monitor.worked(1); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java index fcfe56a2152..60876424601 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java @@ -34,6 +34,10 @@ public abstract class PDOMFullIndexerJob extends Job { protected final PDOM pdom; + // Error count, bail when it gets too high + protected int errorCount; + protected final int MAX_ERRORS = 10; + public PDOMFullIndexerJob(PDOM pdom) { super("Full Indexer: " + pdom.getProject().getElementName()); this.pdom = pdom; @@ -113,9 +117,9 @@ public abstract class PDOMFullIndexerJob extends Job { linkage.addName(name, file); } return PROCESS_CONTINUE; - } catch (CoreException e) { + } catch (Throwable e) { CCorePlugin.log(e); - return PROCESS_ABORT; + return ++errorCount > MAX_ERRORS ? PROCESS_ABORT : PROCESS_CONTINUE; } }; });; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java index d76b9934ba3..9f19810769a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java @@ -72,8 +72,10 @@ public class PDOMFullReindex extends PDOMFullIndexerJob { monitor.subTask(tu.getElementName()); try { addTU(tu); - } catch (InterruptedException e) { - throw new CoreException(Status.CANCEL_STATUS); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + throw new CoreException(Status.CANCEL_STATUS); } monitor.worked(1); } @@ -102,7 +104,9 @@ public class PDOMFullReindex extends PDOMFullIndexerJob { try { addTU(tu); } catch (InterruptedException e) { - throw new CoreException(Status.CANCEL_STATUS); + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + throw new CoreException(Status.CANCEL_STATUS); } } monitor.worked(1);