1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-21 23:33:57 +02:00

Patch for Bogdan Gheorghe

In this patch: 

- Improved error handling for Indexer 
- Improved error handling for MatchLocator 
- Bounds checking for mappings in IncudeEntry 
- Improved error handling for Merge operations 
- Source file name fitering for recreating an already existing index
This commit is contained in:
John Camelon 2004-02-13 22:03:10 +00:00
parent a3fa47a00c
commit bb4821dee3
9 changed files with 373 additions and 327 deletions

View file

@ -1,16 +1,27 @@
2004-02-10 Bogdan Gheorghe 2004-02-13 Bogdan Gheorghe
PR 51232 PR 51232
- Added a layer of separation between the parser and the indexer: we now - Added mapping range checking to IncludeEntry to avoid out of bounds exceptions
create a worker thread to run the parser in. This allows the indexer to - Added error handling to MergeFactory to handle problems during the save operation
finish all scheduled jobs regardless of how the parser performs on - Added source file name filtering for the recreate an already existing index scenario in
individual files (i.e. indexing no longer affected by parser failures) IndexAllProject.
- Added more robust error handling to SourceIndexer
- Added error handling routine to Util.getFileCharContent() to deal with potential out of
memory crash
* index/org/eclipse/cdt/internal/core/index/impl/IncludeEntry.java
* index/org/eclipse/cdt/internal/core/index/impl/MergeFactory.java
* index/org/eclipse/cdt/internal/core/index/search/Util.java
* index/org/eclipse/cdt/internal/core/index/search/indexing/IndexAllProject.java
* index/org/eclipse/cdt/internal/core/index/search/indexing/SourceIndexer.java
* index/org/eclipse/cdt/internal/core/index/search/indexing/AddFolderToIndex.java
2004-02-10 Bogdan Gheorghe
- Modified some of the stored index block reading routines to use separate - Modified some of the stored index block reading routines to use separate
counters, thus avoiding potential EOF exceptions. counters, thus avoiding potential EOF exceptions.
* index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java * index/org/eclipse/cdt/internal/core/index/impl/BlocksIndexInput.java
* index/org/eclipse/cdt/internal/core/index/search/indexing/SourceIndexer.java
2004-02-03 Alain Magloire 2004-02-03 Alain Magloire

View file

@ -148,7 +148,11 @@ public class Util {
try { try {
stream = new BufferedInputStream(new FileInputStream(file)); stream = new BufferedInputStream(new FileInputStream(file));
return Util.getInputStreamAsCharArray(stream, (int) file.length(), encoding); return Util.getInputStreamAsCharArray(stream, (int) file.length(), encoding);
} finally { }
catch (OutOfMemoryError er){
return null;
}
finally {
if (stream != null) { if (stream != null) {
try { try {
stream.close(); stream.close();

View file

@ -157,8 +157,12 @@ public class IncludeEntry {
*/ */
public void mapRefs(int[] mappings) { public void mapRefs(int[] mappings) {
int position= 0; int position= 0;
for (int i= 0; i < fNumRefs; i++) { for (int i= 0; i < fNumRefs; i++) {
int map= mappings[fRefs[i]]; //Take care that the reference is actually within the bounds of the mapping
int map= -1;
if(fRefs[i] >= 0 && fRefs[i] < mappings.length)
map= mappings[fRefs[i]];
if (map != -1 && map != 0) if (map != -1 && map != 0)
fRefs[position++]= map; fRefs[position++]= map;
} }

View file

@ -13,6 +13,9 @@ package org.eclipse.cdt.internal.core.index.impl;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
/** /**
* A mergeFactory is used to merge 2 indexes into one. One of the indexes * A mergeFactory is used to merge 2 indexes into one. One of the indexes
* (oldIndex) is on the disk and the other(addsIndex) is in memory. * (oldIndex) is on the disk and the other(addsIndex) is in memory.
@ -81,7 +84,24 @@ public class MergeFactory {
mergeReferences(); mergeReferences();
mergeIncludes(); mergeIncludes();
mergeOutput.flush(); mergeOutput.flush();
} finally { }
catch ( Exception ex ){
if (ex instanceof IOException)
throw (IOException) ex;
else {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> got the following exception during merge:"); //$NON-NLS-1$
ex.printStackTrace();
}
}
}
catch ( VirtualMachineError er ) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> got the following exception during merge:"); //$NON-NLS-1$
er.printStackTrace();
}
}
finally {
//closes everything //closes everything
oldInput.close(); oldInput.close();
addsInput.close(); addsInput.close();

View file

@ -58,13 +58,12 @@ class AddFolderToIndex extends IndexRequest {
public boolean visit(IResourceProxy proxy) throws CoreException { public boolean visit(IResourceProxy proxy) throws CoreException {
switch(proxy.getType()) { switch(proxy.getType()) {
case IResource.FILE : case IResource.FILE :
// TODO: BOG Put the file name checking back if (Util.isCCFileName(proxy.getName())) {
//if (Util.isJavaFileName(proxy.getName())) {
IResource resource = proxy.requestResource(); IResource resource = proxy.requestResource();
if (pattern == null || !Util.isExcluded(resource, pattern)) if (pattern == null || !Util.isExcluded(resource, pattern))
indexManager.addSource((IFile)resource, container); indexManager.addSource((IFile)resource, container);
//} }
//return false; return false;
case IResource.FOLDER : case IResource.FOLDER :
if (pattern != null && Util.isExcluded(proxy.requestResource(), pattern)) if (pattern != null && Util.isExcluded(proxy.requestResource(), pattern))
return false; return false;

View file

@ -125,8 +125,7 @@ public class IndexAllProject extends IndexRequest {
if (isCancelled) return false; if (isCancelled) return false;
switch(proxy.getType()) { switch(proxy.getType()) {
case IResource.FILE : case IResource.FILE :
// TODO: BOG Put the file name checking back if (Util.isCCFileName(proxy.getName())) {
//if (Util.isCCFileName(proxy.getName())) {
IResource resource = proxy.requestResource(); IResource resource = proxy.requestResource();
IPath path = resource.getLocation(); IPath path = resource.getLocation();
if (path != null && (patterns == null || !Util.isExcluded(resource, patterns))) { if (path != null && (patterns == null || !Util.isExcluded(resource, patterns))) {
@ -136,8 +135,8 @@ public class IndexAllProject extends IndexRequest {
? (Object) resource ? (Object) resource
: (Object) OK); : (Object) OK);
} }
//} }
//return false; return false;
case IResource.FOLDER : case IResource.FOLDER :
if (patterns != null && Util.isExcluded(proxy.requestResource(), patterns)) if (patterns != null && Util.isExcluded(proxy.requestResource(), patterns))
return false; return false;

View file

@ -88,18 +88,9 @@ public class SourceIndexer extends AbstractIndexer {
ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor ), ParserFactory.createScanner( new StringReader( document.getStringContent() ), resourceFile.getLocation().toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor ),
requestor, ParserMode.COMPLETE_PARSE, language ); requestor, ParserMode.COMPLETE_PARSE, language );
ParserRunner p = new ParserRunner(parser);
Thread t = new Thread(p, "CDT Indexer Parser Runner");
t.start();
try{ try{
t.join(); boolean retVal = parser.parse();
}
catch (InterruptedException e){
org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Runner InterruptedException - file: " + resourceFile.getFullPath(), ICLogConstants.CDT);
}
boolean retVal = p.getResult();
if (!retVal) if (!retVal)
org.eclipse.cdt.internal.core.model.Util.log(null, "Failed to index " + resourceFile.getFullPath(), ICLogConstants.CDT); org.eclipse.cdt.internal.core.model.Util.log(null, "Failed to index " + resourceFile.getFullPath(), ICLogConstants.CDT);
@ -110,6 +101,26 @@ public class SourceIndexer extends AbstractIndexer {
else else
AbstractIndexer.verbose("PARSE SUCCEEDED " + resourceFile.getName().toString()); AbstractIndexer.verbose("PARSE SUCCEEDED " + resourceFile.getName().toString());
} }
}
catch ( VirtualMachineError vmErr){
if (vmErr instanceof OutOfMemoryError){
org.eclipse.cdt.internal.core.model.Util.log(null, "Out Of Memory error: " + vmErr.getMessage() + " on File: " + resourceFile.getName(), ICLogConstants.CDT);
}
}
catch ( Exception ex ){
if (ex instanceof IOException)
throw (IOException) ex;
}
finally{
//Release all resources
parser=null;
currentProject = null;
requestor = null;
provider = null;
scanInfo=null;
}
} }
/** /**
* Sets the document types the <code>IIndexer</code> handles. * Sets the document types the <code>IIndexer</code> handles.
@ -122,25 +133,4 @@ public class SourceIndexer extends AbstractIndexer {
return resourceFile; return resourceFile;
} }
class ParserRunner implements Runnable {
IParser parser;
boolean retVal;
ParserRunner(IParser parser){
this.parser = parser;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
try{
retVal=parser.parse();
}
catch (Exception e){
org.eclipse.cdt.internal.core.model.Util.log(null, "Parser Runner Exception " + resourceFile.getFullPath() + " Message: " + e.getMessage(), ICLogConstants.CDT);
}
}
boolean getResult(){ return retVal;}
}
} }

View file

@ -1,3 +1,7 @@
2004-02-13 Bogdan Gheorghe
- Added error handling to MatchLocator.locateMatches to handle possible
parser failures.
2004-02-05 Alain Magloire 2004-02-05 Alain Magloire
PR 51221 PR 51221
Reformat Patch from Bogdan base on Thomas Fletcher original patch Reformat Patch from Bogdan base on Thomas Fletcher original patch

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.search.matching;
import java.io.CharArrayReader; import java.io.CharArrayReader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
@ -440,8 +441,22 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
if (VERBOSE) if (VERBOSE)
MatchLocator.verbose("*** New Search for path: " + pathString); MatchLocator.verbose("*** New Search for path: " + pathString);
try{
parser.parse(); parser.parse();
} }
catch(Exception ex){
if (VERBOSE){
MatchLocator.verbose("MatchLocator Exception: ");
ex.printStackTrace();
}
}
catch(VirtualMachineError vmErr){
if (VERBOSE){
MatchLocator.verbose("MatchLocator VM Error: ");
vmErr.printStackTrace();
}
}
}
} }
protected void report( ISourceElementCallbackDelegate node, int accuracyLevel ){ protected void report( ISourceElementCallbackDelegate node, int accuracyLevel ){