PackMidx: Style fixes like unused throws Minor style fixes reported by analyzers: Remove unnecessary override. Remove throws of exceptions that are not thrown. Avoid RuntimeException (using UncheckedIOException instead) Change-Id: I9cefb1edb696f6ac4cd1b22cec1cb45a6a6a6964
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackMidx.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackMidx.java index 672d0bc..94c3deb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackMidx.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackMidx.java
@@ -23,14 +23,10 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.zip.DataFormatException; -import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.LargeObjectException; -import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.PackInvalidException; -import org.eclipse.jgit.errors.PackMismatchException; import org.eclipse.jgit.internal.storage.midx.MidxMetadataReader; import org.eclipse.jgit.internal.storage.midx.MultiPackIndex; import org.eclipse.jgit.internal.storage.midx.MultiPackIndexLoader; @@ -47,7 +43,7 @@ /** * A pack that uses internally a midx - * + * <p> * This pack answers what it can directly from the midx (e.g. hasObject) and * sends to the right pack other calls (e.g. reading the actual object). */ @@ -92,7 +88,7 @@ public PackMidx(Config cfg, File midxFile, List<Pack> knownPacks) Function.identity())); packsInIdOrder = Arrays.stream(packNames).map(knownPacksByName::get) .filter(Objects::nonNull) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (packsInIdOrder.size() != packNames.length) { throw new IOException("Midx refers to packs not in the pack list"); //$NON-NLS-1$ } @@ -118,11 +114,6 @@ public List<Pack> getCoveredPacks() { } @Override - public PackFile getPackFile() { - return super.getPackFile(); - } - - @Override protected List<Pack> fullyIncludedIn(BitmapIndex.BitmapBuilder needBitmaps) throws IOException { PackBitmapIndex bitmapIndex = getBitmapIndex(); @@ -171,7 +162,7 @@ public boolean hasObjectSizeIndex() throws IOException { } @Override - public long getObjectSizeIndexCount() throws IOException { + public long getObjectSizeIndexCount() { throw new UnsupportedOperationException(); } @@ -245,7 +236,7 @@ ObjectId getPackChecksum() { try { return ObjectId.fromRaw(getMidx().getChecksum()); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -278,12 +269,18 @@ boolean endWindowCache() { @Override ByteArrayWindow read(long pos, int size) throws IOException { MultiPackIndex.PackOffset po = offsetCalculator.decode(pos); + if (po == null) { + throw new IllegalArgumentException("Invalid offset " + pos); + } return packsInIdOrder.get(po.getPackId()).read(po.getOffset(), size); } @Override ByteWindow mmap(long pos, int size) throws IOException { MultiPackIndex.PackOffset po = offsetCalculator.decode(pos); + if (po == null) { + throw new IllegalArgumentException("Invalid offset " + pos); + } return packsInIdOrder.get(po.getPackId()).mmap(po.getOffset(), size); } @@ -291,6 +288,9 @@ ByteWindow mmap(long pos, int size) throws IOException { ObjectLoader load(WindowCursor curs, long pos) throws IOException, LargeObjectException { MultiPackIndex.PackOffset po = offsetCalculator.decode(pos); + if (po == null) { + throw new IllegalArgumentException("Invalid offset " + pos); + } return packsInIdOrder.get(po.getPackId()).load(curs, po.getOffset()); } @@ -298,6 +298,9 @@ ObjectLoader load(WindowCursor curs, long pos) byte[] getDeltaHeader(WindowCursor wc, long pos) throws IOException, DataFormatException { MultiPackIndex.PackOffset po = offsetCalculator.decode(pos); + if (po == null) { + throw new IllegalArgumentException("Invalid offset " + pos); + } return packsInIdOrder.get(po.getPackId()).getDeltaHeader(wc, po.getOffset()); } @@ -305,6 +308,9 @@ ObjectLoader load(WindowCursor curs, long pos) @Override int getObjectType(WindowCursor curs, long pos) throws IOException { MultiPackIndex.PackOffset po = offsetCalculator.decode(pos); + if (po == null) { + throw new IllegalArgumentException("Invalid offset " + pos); + } return packsInIdOrder.get(po.getPackId()).getObjectType(curs, po.getOffset()); } @@ -322,6 +328,9 @@ long getObjectSize(WindowCursor curs, AnyObjectId id) throws IOException { @Override long getObjectSize(WindowCursor curs, long pos) throws IOException { MultiPackIndex.PackOffset po = offsetCalculator.decode(pos); + if (po == null) { + throw new IllegalArgumentException("Invalid offset " + pos); + } return packsInIdOrder.get(po.getPackId()).getObjectSize(curs, po.getOffset()); } @@ -419,7 +428,7 @@ private static class MidxPackIndex implements PackIndex { @Override public Iterator<MutableEntry> iterator() { MultiPackIndex.MidxIterator it = midx.iterator(); - return new Iterator<MutableEntry>() { + return new Iterator<>() { private final MutableEntry me = new MutableEntry(); @@ -477,7 +486,7 @@ public int findPosition(AnyObjectId objId) { @Override public long findCRC32(AnyObjectId objId) - throws MissingObjectException, UnsupportedOperationException { + throws UnsupportedOperationException { throw new UnsupportedOperationException(); } @@ -488,7 +497,7 @@ public boolean hasCRC32Support() { @Override public void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, - int matchLimit) throws IOException { + int matchLimit) { midx.resolve(matches, id, matchLimit); } @@ -512,9 +521,7 @@ private static final class MidxPackReverseIndex } @Override - public void verifyPackChecksum(String packFilePath) - throws PackMismatchException { - + public void verifyPackChecksum(String packFilePath) { } @Override @@ -525,8 +532,7 @@ public ObjectId findObject(long offset) { } @Override - public long findNextOffset(long offset, long maxOffset) - throws CorruptObjectException { + public long findNextOffset(long offset, long maxOffset) { throw new UnsupportedOperationException(); }