Update to the staleness check when loading the PersistentUnitCache
so that a unit that has changed dependencies (but nothing else) will
be properly loaded.

Review at http://gwt-code-reviews.appspot.com/1483803

Review by: tobyr@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10457 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
index 80abe73..f07afbb 100644
--- a/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
+++ b/dev/core/src/com/google/gwt/dev/javac/PersistentUnitCache.java
@@ -500,12 +500,20 @@
                 }
               }
               UnitCacheEntry entry = new UnitCacheEntry(unit, UnitOrigin.PERSISTENT);
-              UnitCacheEntry oldEntry = unitMap.get(unit.getResourcePath());
-              if (oldEntry != null && unit.getLastModified() > oldEntry.getUnit().getLastModified()) {
-                super.remove(oldEntry.getUnit());
+              UnitCacheEntry existingEntry = unitMap.get(unit.getResourcePath());
+              /*
+               * Don't assume that an existing entry is stale - an entry might
+               * have been loaded already from another source like a
+               * CompilationUnitArchive that is more up to date. If the
+               * timestamps are the same, accept the latest version. If it turns
+               * out to be stale, it will be recompiled and the updated unit
+               * will win this test the next time the session starts.
+               */
+              if (existingEntry != null && unit.getLastModified() >= existingEntry.getUnit().getLastModified()) {
+                super.remove(existingEntry.getUnit());
                 unitMap.put(unit.getResourcePath(), entry);
                 unitMapByContentId.put(unit.getContentId(), entry);
-              } else if (oldEntry == null) {
+              } else if (existingEntry == null) {
                 unitMap.put(unit.getResourcePath(), entry);
                 unitMapByContentId.put(unit.getContentId(), entry);
               }