Bug 345548 - [Backport] ObjectNotFoundException prevents opening workspace
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java
index 1df55e5..6335763 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,6 +23,30 @@
import org.eclipse.osgi.util.NLS;
public class SaveManager implements IElementInfoFlattener, IManager, IStringPoolParticipant {
+ class MasterTable extends Properties {
+ private static final long serialVersionUID = 1L;
+
+ /* (non-Javadoc)
+ * @see java.util.Hashtable#put(java.lang.Object, java.lang.Object)
+ */
+ public synchronized Object put(Object key, Object value) {
+ Object prev = super.put(key, value);
+ if (prev != null && ROOT_SEQUENCE_NUMBER_KEY.equals(key)) {
+ int prevSeqNum = new Integer((String) prev).intValue();
+ int currSeqNum = new Integer((String) value).intValue();
+ if (prevSeqNum > currSeqNum) {
+ //revert last put operation
+ super.put(key, prev);
+ //notify about the problem, do not throw exception but add the exception to know where it occurred
+ String message = "Cannot set lower sequence number for root (previous: " + prevSeqNum + ", new: " + currSeqNum + "). Ignoring the new value."; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Policy.log(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, IResourceStatus.INTERNAL_ERROR, message, new IllegalArgumentException(message)));
+ }
+ }
+ return prev;
+ }
+ }
+
+ protected static final String ROOT_SEQUENCE_NUMBER_KEY = Path.ROOT.toString() + LocalMetaArea.F_TREE;
protected static final String CLEAR_DELTA_PREFIX = "clearDelta_"; //$NON-NLS-1$
protected static final String DELTA_EXPIRATION_PREFIX = "deltaExpiration_"; //$NON-NLS-1$
protected static final int DONE_SAVING = 3;
@@ -44,7 +68,7 @@
protected static final String SAVE_NUMBER_PREFIX = "saveNumber_"; //$NON-NLS-1$
protected static final int SAVING = 2;
protected ElementTree lastSnap;
- protected Properties masterTable;
+ protected MasterTable masterTable;
/**
* A flag indicating that a save operation is occurring. This is a signal
@@ -738,7 +762,7 @@
protected void restoreMasterTable() throws CoreException {
long start = System.currentTimeMillis();
- masterTable = new Properties();
+ masterTable = new MasterTable();
IPath location = workspace.getMetaArea().getSafeTableLocationFor(ResourcesPlugin.PI_RESOURCES);
java.io.File target = location.toFile();
if (!target.exists()) {