From ebc2e6aace546036f5759b1659f20078b25887e1 Mon Sep 17 00:00:00 2001 From: Damien Urruty Date: Thu, 7 Dec 2023 09:57:03 +0100 Subject: [PATCH] PR review --- .../intellij/finding/persistence/FindingPersistence.java | 9 ++++++--- .../intellij/finding/persistence/LiveFindingCache.java | 2 +- .../finding/persistence/LiveFindingCacheTests.java | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sonarlint/intellij/finding/persistence/FindingPersistence.java b/src/main/java/org/sonarlint/intellij/finding/persistence/FindingPersistence.java index 7cb07f459c..7ec91198be 100644 --- a/src/main/java/org/sonarlint/intellij/finding/persistence/FindingPersistence.java +++ b/src/main/java/org/sonarlint/intellij/finding/persistence/FindingPersistence.java @@ -72,9 +72,12 @@ public synchronized boolean contains(String key) { return store.contains(key); } - public synchronized void save(String key, Collection findings) throws IOException { - FileUtils.mkdirs(storeBasePath); - store.write(key, transform(findings)); + public void save(String key, Collection findings) throws IOException { + var findingsToWrite = transform(findings); + synchronized (this) { + FileUtils.mkdirs(storeBasePath); + store.write(key, findingsToWrite); + } } public synchronized void clear(String key) throws IOException { diff --git a/src/main/java/org/sonarlint/intellij/finding/persistence/LiveFindingCache.java b/src/main/java/org/sonarlint/intellij/finding/persistence/LiveFindingCache.java index b34f15887f..3a737b386d 100644 --- a/src/main/java/org/sonarlint/intellij/finding/persistence/LiveFindingCache.java +++ b/src/main/java/org/sonarlint/intellij/finding/persistence/LiveFindingCache.java @@ -158,7 +158,7 @@ public void clear() { } public boolean contains(VirtualFile virtualFile) { - return getLive(virtualFile) != null; + return cache.containsKey(virtualFile); } private String createKey(VirtualFile virtualFile) { diff --git a/src/test/java/org/sonarlint/intellij/finding/persistence/LiveFindingCacheTests.java b/src/test/java/org/sonarlint/intellij/finding/persistence/LiveFindingCacheTests.java index e6f4e777be..b8fa07cf9f 100644 --- a/src/test/java/org/sonarlint/intellij/finding/persistence/LiveFindingCacheTests.java +++ b/src/test/java/org/sonarlint/intellij/finding/persistence/LiveFindingCacheTests.java @@ -72,7 +72,7 @@ void should_save_and_read_cache_only() throws IOException { } @Test - void should_flush_if_full() throws IOException { + void should_flush_if_full() { var issue1 = createTestIssue("r1"); var file0 = myFixture.copyFileToProject("foo.php", "foo0.php"); cache.replaceFindings(Map.of(file0, List.of(issue1))); @@ -168,7 +168,6 @@ void testConcurrentAccess() throws Exception { for (Future task : tasks) { task.get(1, TimeUnit.MINUTES); } - } private LiveIssue createTestIssue(String ruleKey) {