### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/index/DiskIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java,v retrieving revision 1.67 diff -u -r1.67 DiskIndex.java --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 27 Jun 2008 16:04:14 -0000 1.67 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 24 Nov 2008 09:49:46 -0000 @@ -12,6 +12,7 @@ import java.io.*; +import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.search.*; import org.eclipse.jdt.internal.core.util.*; @@ -218,7 +219,7 @@ private void cacheDocumentNames() throws IOException { // will need all document names so get them now this.cachedChunks = new String[this.numberOfChunks][]; - FileInputStream stream = new FileInputStream(this.indexFile); + FileInputStream stream = getFileInputStream(); try { if (this.numberOfChunks > 5) BUFFER_READ_SIZE <<= 1; int offset = this.chunkOffsets[0]; @@ -359,6 +360,26 @@ } } } +private FileInputStream getFileInputStream() throws FileNotFoundException { + FileInputStream stream = null; + try { + stream = new FileInputStream(this.indexFile); + } + catch (FileNotFoundException ex) { + Util.log(ex, "It seems that there was an inconsistency in the IndexManager!"); //$NON-NLS-1$ + Util.log(IStatus.ERROR, "The current DiskIndex uses an unexisting file: "+this.indexFile); //$NON-NLS-1$ + Util.log(IStatus.ERROR, " => try to recreate it..."); //$NON-NLS-1$ + try { + initialize(false); + stream = new FileInputStream(this.indexFile); + } catch (IOException e) { + // panic mode + Util.log(e, "Cannot create index file "+this.indexFile); //$NON-NLS-1$ + throw ex; + } + } + return stream; +} void initialize(boolean reuseExistingFile) throws IOException { if (this.indexFile.exists()) { if (reuseExistingFile) { @@ -563,7 +584,7 @@ if (this.numberOfChunks <= 0) return CharOperation.NO_STRINGS; - FileInputStream stream = new FileInputStream(this.indexFile); + FileInputStream stream = getFileInputStream(); try { int offset = this.chunkOffsets[0]; stream.skip(offset); @@ -602,7 +623,7 @@ } } - FileInputStream stream = new FileInputStream(this.indexFile); + FileInputStream stream = getFileInputStream(); HashtableOfObject categoryTable = null; char[][] matchingWords = null; int count = 0; @@ -616,6 +637,7 @@ try { if (size < 0) { // DEBUG System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$ + System.err.println("thread = "+Thread.currentThread()); //$NON-NLS-1$ System.err.println("file = "+this.indexFile); //$NON-NLS-1$ System.err.println("offset = "+offset); //$NON-NLS-1$ System.err.println("size = "+size); //$NON-NLS-1$ @@ -626,6 +648,7 @@ // DEBUG oom.printStackTrace(); System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$ + System.err.println("thread = "+Thread.currentThread()); //$NON-NLS-1$ System.err.println("file = "+this.indexFile); //$NON-NLS-1$ System.err.println("offset = "+offset); //$NON-NLS-1$ System.err.println("size = "+size); //$NON-NLS-1$ @@ -668,7 +691,7 @@ } if (matchingWords != null && count > 0) { - stream = new FileInputStream(this.indexFile); + stream = getFileInputStream(); try { stream.skip(firstOffset); this.bufferIndex = 0; @@ -724,7 +747,7 @@ throw new IllegalArgumentException(); this.streamBuffer = new byte[numberOfBytes]; this.bufferIndex = 0; - FileInputStream file = new FileInputStream(this.indexFile); + FileInputStream file = getFileInputStream(); try { file.skip(start); if (file.read(this.streamBuffer, 0, numberOfBytes) != numberOfBytes) @@ -753,7 +776,7 @@ if (arrayOffset instanceof int[]) return (int[]) arrayOffset; - FileInputStream stream = new FileInputStream(this.indexFile); + FileInputStream stream = getFileInputStream(); try { int offset = ((Integer) arrayOffset).intValue(); stream.skip(offset); Index: search/org/eclipse/jdt/internal/core/index/Index.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/Index.java,v retrieving revision 1.31 diff -u -r1.31 Index.java --- search/org/eclipse/jdt/internal/core/index/Index.java 27 Jun 2008 16:04:14 -0000 1.31 +++ search/org/eclipse/jdt/internal/core/index/Index.java 24 Nov 2008 09:49:46 -0000 @@ -172,6 +172,16 @@ public void remove(String containerRelativePath) { this.memoryIndex.remove(containerRelativePath); } +/** + * Reset memory and disk indexes. + * + * @throws IOException + */ +public void reset(boolean reuseExistingFile) throws IOException { + this.memoryIndex = new MemoryIndex(); + this.diskIndex = new DiskIndex(this.diskIndex.indexFile.getCanonicalPath()); + this.diskIndex.initialize(reuseExistingFile); +} public void save() throws IOException { // must own the write lock of the monitor if (!hasChanged()) return; Index: search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java,v retrieving revision 1.75 diff -u -r1.75 AddJarFileToIndex.java --- search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 27 Jun 2008 16:03:49 -0000 1.75 +++ search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 24 Nov 2008 09:49:46 -0000 @@ -179,8 +179,7 @@ // Index the jar for the first time or reindex the jar in case the previous index file has been corrupted // index already existed: recreate it so that we forget about previous entries SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); - index = this.manager.recreateIndex(this.containerPath); - if (index == null) { + if (!this.manager.resetIndex(this.containerPath)) { // failed to recreate index, see 73330 this.manager.removeIndex(this.containerPath); return false; Index: search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java,v retrieving revision 1.162 diff -u -r1.162 IndexManager.java --- search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 3 Oct 2008 10:47:56 -0000 1.162 +++ search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 24 Nov 2008 09:49:46 -0000 @@ -622,6 +622,35 @@ this.indexLocations = new SimpleLookupTable(); this.javaPluginLocation = null; } +/** + * Resets the index for a given path. + * Returns true if the index was reset, false otherwise. + */ +public synchronized boolean resetIndex(IPath containerPath) { + // only called to over write an existing cached index... + String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); + try { + if (VERBOSE) { + Util.verbose("-> reseting index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ + } + // Path is already canonical + IPath indexLocation = computeIndexLocation(containerPath); + Index index = getIndex(indexLocation); + if (index == null) { + // the index does not exist, try to recreate it + return recreateIndex(containerPath) != null; + } + index.reset(true/*reuse index file*/); + return true; + } catch (IOException e) { + // The file could not be created. Possible reason: the project has been deleted. + if (VERBOSE) { + Util.verbose("-> failed to reset index for path: "+containerPathString); //$NON-NLS-1$ + e.printStackTrace(); + } + return false; + } +} public void saveIndex(Index index) throws IOException { // must have permission to write from the write monitor if (index.hasChanged()) {