Bug 475074 - Data race on
org.eclipse.osgi.framework.internal.reliablefile.ReliableFile.lastGenerationFile
& lastGenerations

Change-Id: Ie4133aaa52cc7b5a8c8cdba7f8ae0c349f4cf7b4
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java
index 1cc8933..f0b0ffb 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2016 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
@@ -404,8 +404,12 @@
 		CacheInfo info = new CacheInfo(FILETYPE_VALID, checksum, newFile.lastModified(), newFile.length());
 		cacheFiles.put(newFile, info);
 		cleanup(generations, true);
-		lastGenerationFile = null;
-		lastGenerations = null;
+		if (!fileSharing) {
+			synchronized (lastGenerationLock) {
+				lastGenerationFile = null;
+				lastGenerations = null;
+			}
+		}
 	}
 
 	/**
@@ -666,8 +670,12 @@
 		ReliableFile rf = new ReliableFile(base);
 		int[] generations = getFileGenerations(base);
 		rf.cleanup(generations, false);
-		lastGenerationFile = null;
-		lastGenerations = null;
+		if (!fileSharing) {
+			synchronized (lastGenerationLock) {
+				lastGenerationFile = null;
+				lastGenerations = null;
+			}
+		}
 	}
 
 	/**
@@ -676,8 +684,12 @@
 	 * @param file
 	 */
 	public static void fileUpdated(File file) {
-		lastGenerationFile = null;
-		lastGenerations = null;
+		if (!fileSharing) {
+			synchronized (lastGenerationLock) {
+				lastGenerationFile = null;
+				lastGenerations = null;
+			}
+		}
 	}
 
 	/**