Fix warnings
ChangeUpdate
* Type safety: The expression of type ArrayList needs unchecked
conversion to conform to List<Comment>
StaticModuleConstants:
* Unnecessary semicolon
FakeQueryChangesTest:
* AbstractFakeIndex is a raw type. References to generic type
AbstractFakeIndex<K,V,D> should be parameterized
* Unnecessary @SuppressWarnings("unchecked")
ExternalIDCacheLoaderTest:
* Resource leak: 'tw' is never closed
* Resource leak: '<unassigned Closeable value>' is never closed
AbstractFakeIndex:
* Redundant specification of type arguments <Integer>
Schema_182:
* Resource leak: 'cleanup' is never closed
AccountConfig:
* Javadoc: The method byAccount(Account.Id, String) in the type
ExternalIds is not applicable for the arguments (Account.Id, ObjectId)
Release-Notes: skip
Change-Id: I05bba425a62ca4f394ac2480cf1603f43cd624c6
Signed-off-by: Edwin Kempin <ekempin@google.com>
Forward-Compatible: checked
diff --git a/java/com/google/gerrit/httpd/raw/StaticModuleConstants.java b/java/com/google/gerrit/httpd/raw/StaticModuleConstants.java
index 23cffa1..f6ac544 100644
--- a/java/com/google/gerrit/httpd/raw/StaticModuleConstants.java
+++ b/java/com/google/gerrit/httpd/raw/StaticModuleConstants.java
@@ -46,5 +46,5 @@
"/settings/*",
"/Documentation/q/*");
- private StaticModuleConstants() {};
+ private StaticModuleConstants() {}
}
diff --git a/java/com/google/gerrit/index/testing/AbstractFakeIndex.java b/java/com/google/gerrit/index/testing/AbstractFakeIndex.java
index 944f956..9412fed 100644
--- a/java/com/google/gerrit/index/testing/AbstractFakeIndex.java
+++ b/java/com/google/gerrit/index/testing/AbstractFakeIndex.java
@@ -85,7 +85,7 @@
this.indexName = indexName;
this.indexedDocuments = new HashMap<>();
this.queryCount = 0;
- this.resultsSizes = new ArrayList<Integer>();
+ this.resultsSizes = new ArrayList<>();
}
@Override
diff --git a/java/com/google/gerrit/server/account/AccountConfig.java b/java/com/google/gerrit/server/account/AccountConfig.java
index e4fa718..2a70d7b 100644
--- a/java/com/google/gerrit/server/account/AccountConfig.java
+++ b/java/com/google/gerrit/server/account/AccountConfig.java
@@ -26,7 +26,6 @@
import com.google.gerrit.entities.RefNames;
import com.google.gerrit.exceptions.DuplicateKeyException;
import com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey;
-import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.CachedPreferences;
import com.google.gerrit.server.git.ValidationError;
@@ -125,7 +124,8 @@
* Returns the revision of the {@code refs/meta/external-ids} branch.
*
* <p>This revision can be used to load the external IDs of the loaded account lazily via {@link
- * ExternalIds#byAccount(com.google.gerrit.entities.Account.Id, ObjectId)}.
+ * com.google.gerrit.server.account.externalids.storage.notedb.ExternalIdsNoteDbImpl#byAccount(com.google.gerrit.entities.Account.Id,
+ * ObjectId)}.
*
* @return revision of the {@code refs/meta/external-ids} branch, {@link Optional#empty()} if no
* {@code refs/meta/external-ids} branch exists
diff --git a/java/com/google/gerrit/server/notedb/ChangeUpdate.java b/java/com/google/gerrit/server/notedb/ChangeUpdate.java
index 23fc000..c9cde96 100644
--- a/java/com/google/gerrit/server/notedb/ChangeUpdate.java
+++ b/java/com/google/gerrit/server/notedb/ChangeUpdate.java
@@ -663,7 +663,7 @@
Map<ObjectId, RevisionNoteBuilder> toUpdate) {
// Prohibit various kinds of illegal operations on comments.
Set<Comment.Key> existing = new HashSet<>();
- List<Comment> draftsToFix = new ArrayList();
+ List<Comment> draftsToFix = new ArrayList<>();
for (ChangeRevisionNote rn : existingNotes.values()) {
for (Comment c : rn.getEntities()) {
existing.add(c.key);
diff --git a/java/com/google/gerrit/server/schema/Schema_182.java b/java/com/google/gerrit/server/schema/Schema_182.java
index a61a175..afb6aac 100644
--- a/java/com/google/gerrit/server/schema/Schema_182.java
+++ b/java/com/google/gerrit/server/schema/Schema_182.java
@@ -28,8 +28,9 @@
public void upgrade(Arguments args, UpdateUI ui) throws Exception {
AllUsersName allUsers = args.allUsers;
GitRepositoryManager gitRepoManager = args.repoManager;
- DeleteZombieCommentsRefs cleanup =
- new DeleteZombieCommentsRefs(allUsers, gitRepoManager, 100, ui::message);
- cleanup.execute();
+ try (DeleteZombieCommentsRefs cleanup =
+ new DeleteZombieCommentsRefs(allUsers, gitRepoManager, 100, ui::message)) {
+ cleanup.execute();
+ }
}
}
diff --git a/javatests/com/google/gerrit/server/account/externalids/storage/notedb/ExternalIDCacheLoaderTest.java b/javatests/com/google/gerrit/server/account/externalids/storage/notedb/ExternalIDCacheLoaderTest.java
index bf38148..03e4278 100644
--- a/javatests/com/google/gerrit/server/account/externalids/storage/notedb/ExternalIDCacheLoaderTest.java
+++ b/javatests/com/google/gerrit/server/account/externalids/storage/notedb/ExternalIDCacheLoaderTest.java
@@ -108,21 +108,23 @@
Repository repo = repoManager.openRepository(ALL_USERS);
ObjectId newState = insertExternalId(key, account);
- TreeWalk tw = new TreeWalk(repo);
- tw.reset(new RevWalk(repo).parseCommit(newState).getTree());
- tw.next();
+ try (TreeWalk tw = new TreeWalk(repo);
+ RevWalk rw = new RevWalk(repo)) {
+ tw.reset(rw.parseCommit(newState).getTree());
+ tw.next();
- HashMap<ObjectId, ObjectId> additions = new HashMap<>();
- additions.put(fileNameToObjectId(tw.getPathString()), tw.getObjectId(0));
- AllExternalIds oldExternalIds =
- AllExternalIds.create(Stream.<ExternalId>builder().add(externalId).build());
+ HashMap<ObjectId, ObjectId> additions = new HashMap<>();
+ additions.put(fileNameToObjectId(tw.getPathString()), tw.getObjectId(0));
+ AllExternalIds oldExternalIds =
+ AllExternalIds.create(Stream.<ExternalId>builder().add(externalId).build());
- AllExternalIds allExternalIds =
- loader.buildAllExternalIds(repo, oldExternalIds, additions, new HashSet<>());
+ AllExternalIds allExternalIds =
+ loader.buildAllExternalIds(repo, oldExternalIds, additions, new HashSet<>());
- assertThat(allExternalIds).isNotNull();
- assertThat(allExternalIds.byKey().containsKey(externalIdKey)).isTrue();
- assertThat(allExternalIds.byKey().get(externalIdKey)).isEqualTo(externalId);
+ assertThat(allExternalIds).isNotNull();
+ assertThat(allExternalIds.byKey().containsKey(externalIdKey)).isTrue();
+ assertThat(allExternalIds.byKey().get(externalIdKey)).isEqualTo(externalId);
+ }
}
private static ObjectId fileNameToObjectId(String path) {
diff --git a/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java b/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java
index 4b87108..161df3a 100644
--- a/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java
+++ b/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java
@@ -119,7 +119,7 @@
@UseClockStep
public void noLimitQueryDoesNotPaginatesWithNonePaginationType() throws Exception {
assumeTrue(PaginationType.NONE == getCurrentPaginationType());
- AbstractFakeIndex idx = setupRepoWithFourChanges();
+ AbstractFakeIndex<?, ?, ?> idx = setupRepoWithFourChanges();
newQuery("status:new").withNoLimit().get();
assertThatSearchQueryWasNotPaginated(idx.getQueryCount());
}
@@ -128,7 +128,7 @@
@UseClockStep
public void invisibleChangesNotPaginatedWithNonePaginationType() throws Exception {
assumeTrue(PaginationType.NONE == getCurrentPaginationType());
- AbstractFakeIndex idx = setupRepoWithFourChanges();
+ AbstractFakeIndex<?, ?, ?> idx = setupRepoWithFourChanges();
final int LIMIT = 3;
projectOperations
@@ -157,7 +157,7 @@
public void invisibleChangesPaginatedWithPagination() throws Exception {
assumeFalse(PaginationType.NONE == getCurrentPaginationType());
- AbstractFakeIndex idx = setupRepoWithFourChanges();
+ AbstractFakeIndex<?, ?, ?> idx = setupRepoWithFourChanges();
final int LIMIT = 3;
projectOperations
@@ -199,7 +199,8 @@
.forUpdate()
.add(allowCapability(QUERY_LIMIT).group(REGISTERED_USERS).range(0, LIMIT))
.update();
- AbstractFakeIndex idx = (AbstractFakeIndex) changeIndexCollection.getSearchIndex();
+ AbstractFakeIndex<?, ?, ?> idx =
+ (AbstractFakeIndex<?, ?, ?>) changeIndexCollection.getSearchIndex();
// 2 index searches are expected. The first index search will run with size 3 (i.e.
// the configured query-limit+1), and then we will paginate to get the remaining
// changes with the second index search.
@@ -209,11 +210,10 @@
@Test
@UseClockStep
- @SuppressWarnings("unchecked")
public void internalQueriesDoNotPaginateWithNonePaginationType() throws Exception {
assumeTrue(PaginationType.NONE == getCurrentPaginationType());
- AbstractFakeIndex idx = setupRepoWithFourChanges();
+ AbstractFakeIndex<?, ?, ?> idx = setupRepoWithFourChanges();
// 1 index search is expected since we are not paginating.
executeQuery("status:new");
assertThatSearchQueryWasNotPaginated(idx.getQueryCount());
@@ -232,7 +232,7 @@
assertThat(queryCount).isEqualTo(expectedPages);
}
- private AbstractFakeIndex setupRepoWithFourChanges() throws Exception {
+ private AbstractFakeIndex<?, ?, ?> setupRepoWithFourChanges() throws Exception {
try (TestRepository<Repository> testRepo = createAndOpenProject("repo")) {
insert("repo", newChange(testRepo));
insert("repo", newChange(testRepo));
@@ -247,6 +247,6 @@
.add(allowCapability(QUERY_LIMIT).group(REGISTERED_USERS).range(0, 2))
.update();
- return (AbstractFakeIndex) changeIndexCollection.getSearchIndex();
+ return (AbstractFakeIndex<?, ?, ?>) changeIndexCollection.getSearchIndex();
}
}