From b5941c74e59e64c5fd374a09067e74e26eed2612 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sun, 26 Jul 2015 14:42:52 +0200 Subject: [PATCH] Set "potentialNullReference" to "error" level and fixed all issues There should be no functional change, the logic updated only to make code simple so that compiler can understand what is going for. Removed all @SuppressWarnings("null") annotations since they cannot be used if "org.eclipse.jdt.core.compiler.problem.potentialNullReference" option is set to the "error" level. Bug: 470647 Change-Id: Ie93c249fa46e792198d362e531d5cbabaf41fdc4 Signed-off-by: Andrey Loskutov --- .../.settings/org.eclipse.jdt.core.prefs | 2 +- .../eclipse/jgit/dircache/DirCacheTree.java | 1 + .../internal/storage/dfs/DfsPackFile.java | 24 ++++++++++++------ .../jgit/internal/storage/file/PackFile.java | 25 +++++++++++++------ .../internal/storage/file/RefDirectory.java | 3 ++- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs index 32de0e9ce..4e28e0b26 100644 --- a/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.jgit/.settings/org.eclipse.jdt.core.prefs @@ -71,7 +71,7 @@ org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error -org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning +org.eclipse.jdt.core.compiler.problem.potentialNullReference=error org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java index 83aa8fa4d..f139afc00 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java @@ -478,6 +478,7 @@ public class DirCacheTree { // The entry is contained in this subtree. // + assert(st != null); st.validate(cache, cCnt, cIdx, pathOff + st.nameLength() + 1); cIdx += st.entrySpan; entrySpan += st.entrySpan; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java index 75b0646ed..96f1d542c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java @@ -533,7 +533,6 @@ public final class DfsPackFile { return ByteBuffer.wrap(copyBuf, 0, bs); } - @SuppressWarnings("null") void copyAsIs(PackOutputStream out, DfsObjectToPack src, boolean validate, DfsReader ctx) throws IOException, StoredObjectRepresentationNotAvailableException { @@ -567,22 +566,26 @@ public final class DfsPackFile { c = buf[headerCnt++] & 0xff; } while ((c & 128) != 0); if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, headerCnt); crc2.update(buf, 0, headerCnt); } } else if (typeCode == Constants.OBJ_REF_DELTA) { if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, headerCnt); crc2.update(buf, 0, headerCnt); } readFully(src.offset + headerCnt, buf, 0, 20, ctx); if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, 20); crc2.update(buf, 0, 20); } headerCnt += 20; } else if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, headerCnt); crc2.update(buf, 0, headerCnt); } @@ -599,6 +602,7 @@ public final class DfsPackFile { quickCopy = ctx.quickCopy(this, dataOffset, dataLength); if (validate && idx(ctx).hasCRC32Support()) { + assert(crc1 != null); // Index has the CRC32 code cached, validate the object. // expectedCRC = idx(ctx).findCRC32(src); @@ -622,6 +626,7 @@ public final class DfsPackFile { Long.valueOf(src.offset), getPackName())); } } else if (validate) { + assert(crc1 != null); // We don't have a CRC32 code in the index, so compute it // now while inflating the raw data to get zlib to tell us // whether or not the data is safe. @@ -709,16 +714,21 @@ public final class DfsPackFile { while (cnt > 0) { final int n = (int) Math.min(cnt, buf.length); readFully(pos, buf, 0, n, ctx); - if (validate) + if (validate) { + assert(crc2 != null); crc2.update(buf, 0, n); + } out.write(buf, 0, n); pos += n; cnt -= n; } - if (validate && crc2.getValue() != expectedCRC) { - throw new CorruptObjectException(MessageFormat.format( - JGitText.get().objectAtHasBadZlibStream, - Long.valueOf(src.offset), getPackName())); + if (validate) { + assert(crc2 != null); + if (crc2.getValue() != expectedCRC) { + throw new CorruptObjectException(MessageFormat.format( + JGitText.get().objectAtHasBadZlibStream, + Long.valueOf(src.offset), getPackName())); + } } } } @@ -837,7 +847,6 @@ public final class DfsPackFile { return buf.position(); } - @SuppressWarnings("null") ObjectLoader load(DfsReader ctx, long pos) throws IOException { try { @@ -934,6 +943,7 @@ public final class DfsPackFile { if (data == null) throw new LargeObjectException(); + assert(delta != null); do { // Cache only the base immediately before desired object. if (cached) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java index b29966eac..589a81173 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java @@ -366,7 +366,6 @@ public class PackFile implements Iterable { } } - @SuppressWarnings("null") private void copyAsIs2(PackOutputStream out, LocalObjectToPack src, boolean validate, WindowCursor curs) throws IOException, StoredObjectRepresentationNotAvailableException { @@ -393,22 +392,26 @@ public class PackFile implements Iterable { c = buf[headerCnt++] & 0xff; } while ((c & 128) != 0); if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, headerCnt); crc2.update(buf, 0, headerCnt); } } else if (typeCode == Constants.OBJ_REF_DELTA) { if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, headerCnt); crc2.update(buf, 0, headerCnt); } readFully(src.offset + headerCnt, buf, 0, 20, curs); if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, 20); crc2.update(buf, 0, 20); } headerCnt += 20; } else if (validate) { + assert(crc1 != null && crc2 != null); crc1.update(buf, 0, headerCnt); crc2.update(buf, 0, headerCnt); } @@ -425,6 +428,7 @@ public class PackFile implements Iterable { quickCopy = curs.quickCopy(this, dataOffset, dataLength); if (validate && idx().hasCRC32Support()) { + assert(crc1 != null); // Index has the CRC32 code cached, validate the object. // expectedCRC = idx().findCRC32(src); @@ -457,6 +461,7 @@ public class PackFile implements Iterable { if (quickCopy != null) { quickCopy.check(inf, tmp, dataOffset, (int) dataLength); } else { + assert(crc1 != null); long pos = dataOffset; long cnt = dataLength; while (cnt > 0) { @@ -476,6 +481,7 @@ public class PackFile implements Iterable { JGitText.get().shortCompressedStreamAt, Long.valueOf(src.offset))); } + assert(crc1 != null); expectedCRC = crc1.getValue(); } else { expectedCRC = -1; @@ -535,16 +541,21 @@ public class PackFile implements Iterable { while (cnt > 0) { final int n = (int) Math.min(cnt, buf.length); readFully(pos, buf, 0, n, curs); - if (validate) + if (validate) { + assert(crc2 != null); crc2.update(buf, 0, n); + } out.write(buf, 0, n); pos += n; cnt -= n; } - if (validate && crc2.getValue() != expectedCRC) { - throw new CorruptObjectException(MessageFormat.format( - JGitText.get().objectAtHasBadZlibStream, - Long.valueOf(src.offset), getPackFile())); + if (validate) { + assert(crc2 != null); + if (crc2.getValue() != expectedCRC) { + throw new CorruptObjectException(MessageFormat.format( + JGitText.get().objectAtHasBadZlibStream, + Long.valueOf(src.offset), getPackFile())); + } } } } @@ -712,7 +723,6 @@ public class PackFile implements Iterable { , getPackFile())); } - @SuppressWarnings("null") ObjectLoader load(final WindowCursor curs, long pos) throws IOException, LargeObjectException { try { @@ -811,6 +821,7 @@ public class PackFile implements Iterable { if (data == null) throw new IOException(JGitText.get().inMemoryBufferLimitExceeded); + assert(delta != null); do { // Cache only the base immediately before desired object. if (cached) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 6d6d0cabd..c7b60882a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -881,7 +881,6 @@ public class RefDirectory extends RefDatabase { return n; } - @SuppressWarnings("null") private LooseRef scanRef(LooseRef ref, String name) throws IOException { final File path = fileFor(name); FileSnapshot currentSnapshot = null; @@ -920,6 +919,7 @@ public class RefDirectory extends RefDatabase { final String target = RawParseUtils.decode(buf, 5, n); if (ref != null && ref.isSymbolic() && ref.getTarget().getName().equals(target)) { + assert(currentSnapshot != null); currentSnapshot.setClean(otherSnapshot); return ref; } @@ -934,6 +934,7 @@ public class RefDirectory extends RefDatabase { id = ObjectId.fromString(buf, 0); if (ref != null && !ref.isSymbolic() && ref.getTarget().getObjectId().equals(id)) { + assert(currentSnapshot != null); currentSnapshot.setClean(otherSnapshot); return ref; }