From d8cb554f25925f3ea2d66815fdaa59efa1867ae3 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sun, 28 Apr 2024 21:28:30 +0200 Subject: [errorprone] Fix UnnecessaryParentheses errors See https://errorprone.info/bugpattern/UnnecessaryParentheses Change-Id: I783fd24286ec1bd55efbf21d05758465f4af87ee --- .../eclipse/jgit/junit/ssh/SshTestGitServer.java | 2 +- .../tst/org/eclipse/jgit/pgm/CloneTest.java | 4 +- .../tst/org/eclipse/jgit/pgm/ConfigTest.java | 5 +-- .../tst/org/eclipse/jgit/api/AddCommandTest.java | 4 +- .../jgit/attributes/TreeWalkAttributeTest.java | 2 +- .../internal/storage/dfs/DfsPackParserTest.java | 4 +- .../org/eclipse/jgit/transport/PackParserTest.java | 26 ++++++------- .../ReceivePackAdvertiseRefsHookTest.java | 6 +-- .../org/eclipse/jgit/transport/UploadPackTest.java | 43 ++++++++++++---------- tools/BUILD | 2 +- 10 files changed, 50 insertions(+), 48 deletions(-) diff --git a/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java b/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java index 1138be8a96..f5627e00c8 100644 --- a/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java +++ b/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java @@ -323,7 +323,7 @@ public class SshTestGitServer { server.setFileSystemFactory(new VirtualFileSystemFactory(repository .getDirectory().getParentFile().getAbsoluteFile().toPath())); return Collections - .singletonList((new SftpSubsystemFactory.Builder()).build()); + .singletonList(new SftpSubsystemFactory.Builder().build()); } /** diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java index cbb5bbb9cc..a1fb9fb589 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java @@ -183,7 +183,7 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourcePath = gitDir.getAbsolutePath(); - String targetPath = (new File(sourcePath)).getParentFile() + String targetPath = new File(sourcePath).getParentFile() .getParentFile().getAbsolutePath() + File.separator + "target.git"; String cmd = "git clone --bare " + shellQuote(sourcePath) + " " @@ -207,7 +207,7 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourcePath = gitDir.getAbsolutePath(); - String targetPath = (new File(sourcePath)).getParentFile() + String targetPath = new File(sourcePath).getParentFile() .getParentFile().getAbsolutePath() + File.separator + "target.git"; String cmd = "git clone --mirror " + shellQuote(sourcePath) + " " diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java index 005215f443..0af310c497 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ConfigTest.java @@ -45,10 +45,9 @@ public class ConfigTest extends CLIRepositoryTestCase { Map options = parseOptions(output); assertEquals(!isWindows, Boolean.valueOf(options.get("core.filemode"))); - assertTrue((Boolean.valueOf(options.get("core.logallrefupdates")))); + assertTrue(Boolean.valueOf(options.get("core.logallrefupdates"))); if (isMac) { - assertTrue( - (Boolean.valueOf(options.get("core.precomposeunicode")))); + assertTrue(Boolean.valueOf(options.get("core.precomposeunicode"))); } assertEquals(Integer.valueOf(0), Integer.valueOf(options.get("core.repositoryformatversion"))); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index db2d5d1404..aa65985c55 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java @@ -1259,7 +1259,7 @@ public class AddCommandTest extends RepositoryTestCase { "[git-link-dir, mode:160000]", indexState(0)); Set untrackedFiles = git.status().call().getUntracked(); - assert (untrackedFiles.isEmpty()); + assert untrackedFiles.isEmpty(); } } @@ -1274,7 +1274,7 @@ public class AddCommandTest extends RepositoryTestCase { ConfigConstants.CONFIG_KEY_DIRNOGITLINKS, true); config.save(); - assert (db.getConfig().get(WorkingTreeOptions.KEY).isDirNoGitLinks()); + assert db.getConfig().get(WorkingTreeOptions.KEY).isDirNoGitLinks(); try (Git git = new Git(db)) { git.add().addFilepattern("nested-repo").call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java index 73abd2d37e..698fdb31a8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java @@ -791,7 +791,7 @@ public class TreeWalkAttributeTest extends RepositoryTestCase { for (Attribute a : attributes) { ret.add(a); } - return (ret); + return ret; } private File writeAttributesFile(String name, String... rules) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java index 845d5fcca1..130af27773 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java @@ -46,10 +46,10 @@ public class DfsPackParserTest { .fromString("2e65efe2a145dda7ee51d1741299f848e5bf752e"); pack.header(2); - pack.write((Constants.OBJ_BLOB) << 4 | 1); + pack.write(Constants.OBJ_BLOB << 4 | 1); pack.deflate(new byte[] { 'a' }); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(blobA); pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' }); pack.digest(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java index 2fd82e7bdb..6148df99f3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java @@ -191,7 +191,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(a); pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' }); pack.digest(); @@ -211,7 +211,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_BLOB) << 4 | 0x80 | 1); + pack.write(Constants.OBJ_BLOB << 4 | 0x80 | 1); pack.write(1); pack.deflate(data); pack.digest(); @@ -231,9 +231,9 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(2); - pack.write((Constants.OBJ_BLOB) << 4 | 10); // offset 12 + pack.write(Constants.OBJ_BLOB << 4 | 10); // offset 12 pack.deflate(data); - pack.write((Constants.OBJ_OFS_DELTA) << 4 | 4); // offset 31 + pack.write(Constants.OBJ_OFS_DELTA << 4 | 4); // offset 31 pack.write(19); pack.deflate(new byte[] { 0xA, 0xB, 0x1, 'b' }); pack.digest(); @@ -270,7 +270,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(a); pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' }); pack.digest(); @@ -300,7 +300,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_BLOB) << 4 | 10); + pack.write(Constants.OBJ_BLOB << 4 | 10); pack.deflate(data); pack.digest(); @@ -333,7 +333,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 14); + pack.write(Constants.OBJ_REF_DELTA << 4 | 14); pack.copyRaw(a); pack.deflate(new byte[] { 1, 11, 11, 'a', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }); @@ -366,7 +366,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(a); pack.deflate(new byte[] { 10, 11, 1, 'a' }); pack.digest(); @@ -398,7 +398,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(a); pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' }); pack.digest(); @@ -439,7 +439,7 @@ public class PackParserTest extends RepositoryTestCase { InMemoryPack pack = new InMemoryPack(); pack.header(1); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(a); pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' }); pack.digest(); @@ -470,7 +470,7 @@ public class PackParserTest extends RepositoryTestCase { pack.header(objects); for (int i = 0; i < objects; i++) { - pack.write((Constants.OBJ_BLOB) << 4 | 10); + pack.write(Constants.OBJ_BLOB << 4 | 10); pack.deflate(data); } pack.digest(); @@ -508,7 +508,7 @@ public class PackParserTest extends RepositoryTestCase { for (int i = 0; i < offset; i++) sb.append(i); offset = sb.toString().length(); - int lenByte = (Constants.OBJ_BLOB) << 4 | (offset & 0x0F); + int lenByte = Constants.OBJ_BLOB << 4 | (offset & 0x0F); offset >>= 4; if (offset > 0) lenByte |= 1 << 7; @@ -525,7 +525,7 @@ public class PackParserTest extends RepositoryTestCase { for (int i = 0; i < objects; i++) { // The last pack header written falls across the 8192 byte boundary // between [8189:8210] - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); pack.copyRaw(b); pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' }); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java index a91bc95c8d..7dac27f612 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java @@ -187,10 +187,10 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); packHeader(pack, 2); - pack.write((Constants.OBJ_BLOB) << 4 | 1); + pack.write(Constants.OBJ_BLOB << 4 | 1); deflate(pack, new byte[] { 'a' }); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); a.copyRawTo(pack); deflate(pack, new byte[] { 0x1, 0x1, 0x1, 'b' }); @@ -296,7 +296,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas packHeader(pack, 3); copy(pack, src.open(N)); copy(pack, src.open(s.parseBody(N).getTree())); - pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + pack.write(Constants.OBJ_REF_DELTA << 4 | 4); b.copyRawTo(pack); deflate(pack, delta); digest(pack); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 026492f7b6..def73acadd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -1800,14 +1800,15 @@ public class UploadPackTest { RevBlob blobHighDepth = remote.blob("hi"); RevTree subtree = remote.tree(remote.file("1", blobHighDepth)); - RevTree rootTree = (new TreeBuilder() { + + RevTree rootTree = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.add(remote.file("1", blobLowDepth)); dcBuilder.addTree(new byte[] {'2'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree); } - }).build(); + }.build(); RevCommit commit = remote.commit(rootTree); DeepTreePreparator() throws Exception {} @@ -1904,21 +1905,23 @@ public class UploadPackTest { class RepeatedSubtreePreparator { RevBlob foo = remote.blob("foo"); RevTree subtree3 = remote.tree(remote.file("foo", foo)); - RevTree subtree2 = (new TreeBuilder() { + RevTree subtree2 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'b'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree3); } - }).build(); - RevTree subtree1 = (new TreeBuilder() { + }.build(); + + RevTree subtree1 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'x'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree2); } - }).build(); - RevTree rootTree = (new TreeBuilder() { + }.build(); + + RevTree rootTree = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'a'}, DirCacheEntry.STAGE_0, @@ -1926,7 +1929,7 @@ public class UploadPackTest { dcBuilder.addTree(new byte[] {'x'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree2); } - }).build(); + }.build(); RevCommit commit = remote.commit(rootTree); RepeatedSubtreePreparator() throws Exception {} @@ -1970,22 +1973,22 @@ public class UploadPackTest { RevTree subtree1 = remote.tree(remote.file("foo", foo)); /** b/foo */ - RevTree subtree2 = (new TreeBuilder() { + RevTree subtree2 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'b'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree1); } - }).build(); + }.build(); /** x/b/foo */ - RevTree subtree3 = (new TreeBuilder() { + RevTree subtree3 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'x'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree2); } - }).build(); + }.build(); RevBlob baz = remote.blob("baz"); @@ -1993,33 +1996,33 @@ public class UploadPackTest { RevTree subtree4 = remote.tree(remote.file("baz", baz)); /** c/baz */ - RevTree subtree5 = (new TreeBuilder() { + RevTree subtree5 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'c'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree4); } - }).build(); + }.build(); /** u/c/baz */ - RevTree subtree6 = (new TreeBuilder() { + RevTree subtree6 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'u'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree5); } - }).build(); + }.build(); /** v/c/baz */ - RevTree subtree7 = (new TreeBuilder() { + RevTree subtree7 = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'v'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree5); } - }).build(); + }.build(); - RevTree rootTree = (new TreeBuilder() { + RevTree rootTree = new TreeBuilder() { @Override void addElements(DirCacheBuilder dcBuilder) throws Exception { dcBuilder.addTree(new byte[] {'a'}, DirCacheEntry.STAGE_0, @@ -2031,7 +2034,7 @@ public class UploadPackTest { dcBuilder.addTree(new byte[] {'z'}, DirCacheEntry.STAGE_0, remote.getRevWalk().getObjectReader(), subtree7); } - }).build(); + }.build(); RevCommit commit = remote.commit(rootTree); RepeatedSubtreeAtSameLevelPreparator() throws Exception {} diff --git a/tools/BUILD b/tools/BUILD index c2b2366c49..dbec43b7fa 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -396,7 +396,7 @@ java_package_configuration( "-Xep:UnnecessaryLambda:ERROR", "-Xep:UnnecessaryMethodInvocationMatcher:ERROR", "-Xep:UnnecessaryMethodReference:ERROR", - "-Xep:UnnecessaryParentheses:WARN", + "-Xep:UnnecessaryParentheses:ERROR", "-Xep:UnnecessaryTypeArgument:ERROR", "-Xep:UnrecognisedJavadocTag:ERROR", "-Xep:UnsafeFinalization:ERROR", -- cgit v1.2.3