Fix error prone errors
Gerrit is offering custom build tool chain with enabled more strict
error prone severity level, where much more error prone pattern are
turned to errors.
Right now, only gerrit core and core plugins are enabled for extended
error prone tool chain. To enable it for custom plugins, its package
should be added to error_prone_packages package_group in tools/BUILD
file in gerrit core:
package_group(
name = "error_prone_packages",
packages = [
"//plugins/multi-site/...",
[...]
Change-Id: Ie71ef939d28011cfd5af402d056cefd8165d9fc9
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/cache/CachePatternMatcher.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/cache/CachePatternMatcher.java
index b8521a3..2dcb09a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/cache/CachePatternMatcher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/cache/CachePatternMatcher.java
@@ -25,7 +25,7 @@
@Singleton
class CachePatternMatcher {
- private static final List<String> DEFAULT_PATTERNS =
+ private static final ImmutableList<String> DEFAULT_PATTERNS =
ImmutableList.of("^groups.*", "ldap_groups", "ldap_usernames", "projects", "sshkeys");
private final Pattern pattern;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java
index ce6804e..6da9681 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandler.java
@@ -23,6 +23,7 @@
import com.googlesource.gerrit.plugins.multisite.index.ForwardedIndexExecutor;
import com.googlesource.gerrit.plugins.multisite.index.ProjectChecker;
import java.util.Optional;
+import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -92,20 +93,22 @@
projectName,
retryInterval);
- indexExecutor.schedule(
- () -> {
- Context.setForwardedEvent(true);
- if (!attemptIndex(projectName, event)) {
- log.warn(
- "Attempt {} to index project {} failed, scheduling again after {} msecs",
- retryCount,
- projectName,
- retryInterval);
- rescheduleIndex(projectName, event, retryCount + 1);
- }
- },
- retryInterval,
- TimeUnit.MILLISECONDS);
+ @SuppressWarnings("unused")
+ Future<?> possiblyIgnoredError =
+ indexExecutor.schedule(
+ () -> {
+ Context.setForwardedEvent(true);
+ if (!attemptIndex(projectName, event)) {
+ log.warn(
+ "Attempt {} to index project {} failed, scheduling again after {} msecs",
+ retryCount,
+ projectName,
+ retryInterval);
+ rescheduleIndex(projectName, event, retryCount + 1);
+ }
+ },
+ retryInterval,
+ TimeUnit.MILLISECONDS);
}
@Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
index 28eddbb..ea7dada 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
@@ -36,7 +36,6 @@
import com.googlesource.gerrit.plugins.multisite.forwarder.Context;
import java.io.IOException;
import java.util.Optional;
-import java.util.Set;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
@@ -48,7 +47,7 @@
@Singleton
public class ProjectVersionRefUpdate implements EventListener {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- private static final Set<RefUpdate.Result> SUCCESSFUL_RESULTS =
+ private static final ImmutableSet<RefUpdate.Result> SUCCESSFUL_RESULTS =
ImmutableSet.of(RefUpdate.Result.NEW, RefUpdate.Result.FORCED, RefUpdate.Result.NO_CHANGE);
public static final String MULTI_SITE_VERSIONING_REF = "refs/multi-site/version";
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/BrokerForwarderTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/BrokerForwarderTest.java
index 5e2fc05..74d8917 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/BrokerForwarderTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/BrokerForwarderTest.java
@@ -67,7 +67,7 @@
}
}
- public class TestEvent extends MultiSiteEvent {
+ public static class TestEvent extends MultiSiteEvent {
protected TestEvent() {
super("test");
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
index 90ae8da..dbd358d 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedCacheEvictionHandlerTest.java
@@ -15,6 +15,7 @@
package com.googlesource.gerrit.plugins.multisite.forwarder;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import static org.mockito.Mockito.doReturn;
import com.google.common.cache.Cache;
@@ -48,10 +49,12 @@
public void shouldThrowAnExceptionWhenCacheNotFound() throws Exception {
CacheEntry entry = new CacheEntry("somePlugin", "unexistingCache", null);
- exception.expect(CacheNotFoundException.class);
- exception.expectMessage(
- String.format("cache %s.%s not found", entry.getPluginName(), entry.getCacheName()));
- handler.evict(entry);
+ CacheNotFoundException thrown =
+ assertThrows(CacheNotFoundException.class, () -> handler.evict(entry));
+ assertThat(thrown)
+ .hasMessageThat()
+ .isEqualTo(
+ String.format("cache %s.%s not found", entry.getPluginName(), entry.getCacheName()));
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java
index 32c6319..02efb77 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexAccountHandlerTest.java
@@ -61,9 +61,11 @@
@Test
public void deleteIsNotSupported() throws Exception {
- exception.expect(UnsupportedOperationException.class);
- exception.expectMessage("Delete from account index not supported");
- handler.index(id, Operation.DELETE, Optional.empty());
+ UnsupportedOperationException thrown =
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> handler.index(id, Operation.DELETE, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("Delete from account index not supported");
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java
index c52dfff..04d83c5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexChangeHandlerTest.java
@@ -125,8 +125,9 @@
@Test
public void indexerThrowsStorageExceptionTryingToIndexChange() throws Exception {
setupChangeAccessRelatedMocks(CHANGE_EXISTS, THROW_STORAGE_EXCEPTION, CHANGE_UP_TO_DATE);
- exception.expect(StorageException.class);
- handler.index(TEST_CHANGE_ID, Operation.INDEX, Optional.empty());
+ assertThrows(
+ StorageException.class,
+ () -> handler.index(TEST_CHANGE_ID, Operation.INDEX, Optional.empty()));
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java
index 2fe6e2e..c703512 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexGroupHandlerTest.java
@@ -61,9 +61,11 @@
@Test
public void deleteIsNotSupported() throws Exception {
- exception.expect(UnsupportedOperationException.class);
- exception.expectMessage("Delete from group index not supported");
- handler.index(uuid, Operation.DELETE, Optional.empty());
+ UnsupportedOperationException thrown =
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> handler.index(uuid, Operation.DELETE, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("Delete from group index not supported");
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java
index 1102cd2..9ed0f7d 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/forwarder/ForwardedIndexProjectHandlerTest.java
@@ -71,9 +71,11 @@
@Test
public void deleteIsNotSupported() throws Exception {
- exception.expect(UnsupportedOperationException.class);
- exception.expectMessage("Delete from project index not supported");
- handler.index(nameKey, Operation.DELETE, Optional.empty());
+ UnsupportedOperationException thrown =
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> handler.index(nameKey, Operation.DELETE, Optional.empty()));
+ assertThat(thrown).hasMessageThat().isEqualTo("Delete from project index not supported");
}
@Test