diff options
Diffstat (limited to 'sonar-home')
-rw-r--r-- | sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java | 3 | ||||
-rw-r--r-- | sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java index dfc94827d0b..991fadf8cdc 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java @@ -90,6 +90,9 @@ public class PersistentCache { try { lock(); Path path = getCacheCopy(key); + if (path == null) { + return null; + } return new DeleteFileOnCloseInputStream(new FileInputStream(path.toFile()), path); } finally { diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java index 77ee30908e1..5063fbdb22f 100644 --- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java +++ b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java @@ -19,7 +19,11 @@ */ package org.sonar.home.cache; +import org.apache.commons.io.IOUtils; + import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -72,6 +76,15 @@ public class PersistentCacheTest { } @Test + public void testStream() throws IOException { + cache.put("id", "test".getBytes()); + InputStream stream = cache.getStream("id"); + assertThat(IOUtils.toString(stream)).isEqualTo("test"); + + assertThat(cache.getStream("non existing")).isNull(); + } + + @Test public void testClear() throws Exception { Path lockFile = cache.getDirectory().resolve("lock"); cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); |