Close CommitReceiveEvent in CodeOwnersPluginConfigValidatorTest Wrap the creation of CommitReceiveEvent inside a try-with-resource for avoiding leaving a resource leak that will eventually result into a Repository reference counting leak. Even though this is not impacting the production code it would anyway respresent a false positive when looking for Repository reference counting leaks. Change-Id: I326f2140916021d064603db12d0f19368e9a8fd3
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java index 0957119..479ad1d 100644 --- a/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java +++ b/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginConfigValidatorTest.java
@@ -75,18 +75,21 @@ .add("project.config", "INVALID") .create(); - CommitReceivedEvent receiveEvent = new CommitReceivedEvent(); - receiveEvent.project = - projectCache.get(project).orElseThrow(illegalState(project)).getProject(); - receiveEvent.refName = RefNames.REFS_CONFIG; - receiveEvent.commit = commit; - receiveEvent.revWalk = testRepo.getRevWalk(); - receiveEvent.repoConfig = new Config(); - receiveEvent.diffOperations = diffOperationsForCommitValidationFactory.create(repoView, ins); - CommitValidationException exception = - assertThrows( - CommitValidationException.class, - () -> codeOwnersPluginConfigValidator.onCommitReceived(receiveEvent)); + CommitValidationException exception; + try (CommitReceivedEvent receiveEvent = new CommitReceivedEvent()) { + receiveEvent.project = + projectCache.get(project).orElseThrow(illegalState(project)).getProject(); + receiveEvent.refName = RefNames.REFS_CONFIG; + receiveEvent.commit = commit; + receiveEvent.revWalk = testRepo.getRevWalk(); + receiveEvent.repoConfig = new Config(); + receiveEvent.diffOperations = + diffOperationsForCommitValidationFactory.create(repoView, ins); + exception = + assertThrows( + CommitValidationException.class, + () -> codeOwnersPluginConfigValidator.onCommitReceived(receiveEvent)); + } assertThat(exception) .hasMessageThat() .isEqualTo(