diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 9c5a1e32d..4d7be0a4c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -294,6 +294,10 @@ public static FileStoreAttributes get(Path path) { return cached; } FileStoreAttributes attrs = getFileStoreAttributes(dir); + if (attrs == null) { + // Don't cache, result might be late + return FALLBACK_FILESTORE_ATTRIBUTES; + } attrCacheByPath.put(dir, attrs); return attrs; } catch (SecurityException e) { @@ -382,12 +386,16 @@ private static FileStoreAttributes getFileStoreAttributes(Path dir) { }); // even if measuring in background wait a little - if the result // arrives, it's better than returning the large fallback - Optional d = background.get() ? f.get( + boolean runInBackground = background.get(); + Optional d = runInBackground ? f.get( 100, TimeUnit.MILLISECONDS) : f.get(); if (d.isPresent()) { return d.get(); + } else if (runInBackground) { + // return null until measurement is finished + return null; } - // return fallback until measurement is finished + // fall through and return fallback } catch (IOException | InterruptedException | ExecutionException | CancellationException e) { LOG.error(e.getMessage(), e);