Fix NarrowingCompoundAssignment warnings from Error Prone

Error Prone reports:

  [NarrowingCompoundAssignment] Compound assignments from long to int
  hide lossy casts

and

  [NarrowingCompoundAssignment] Compound assignments from int to byte
  hide lossy casts

  See https://errorprone.info/bugpattern/NarrowingCompoundAssignment

Fix the warnings by adding explicit casts or changing types as
necessary.

Now that all occurrences of the warning are fixed, increase its
severity to ERROR.

Change-Id: Idb3670e6047b146ae37daee07212ff9455512623
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2019-06-22 18:47:43 +09:00 committed by Matthias Sohn
parent aefb11298c
commit 72ae089206
10 changed files with 18 additions and 17 deletions

View File

@ -842,9 +842,9 @@ public ObjectReader newReader() {
* Throws an exception if reading beyond limit. * Throws an exception if reading beyond limit.
*/ */
static class BigReadForbiddenStream extends ObjectStream.Filter { static class BigReadForbiddenStream extends ObjectStream.Filter {
int limit; long limit;
BigReadForbiddenStream(ObjectStream orig, int limit) { BigReadForbiddenStream(ObjectStream orig, long limit) {
super(orig.getType(), orig.getSize(), orig); super(orig.getType(), orig.getSize(), orig);
this.limit = limit; this.limit = limit;
} }

View File

@ -448,9 +448,9 @@ public boolean isAssumeValid() {
*/ */
public void setAssumeValid(boolean assume) { public void setAssumeValid(boolean assume) {
if (assume) if (assume)
info[infoOffset + P_FLAGS] |= ASSUME_VALID; info[infoOffset + P_FLAGS] |= (byte) ASSUME_VALID;
else else
info[infoOffset + P_FLAGS] &= ~ASSUME_VALID; info[infoOffset + P_FLAGS] &= (byte) ~ASSUME_VALID;
} }
/** /**
@ -470,9 +470,9 @@ public boolean isUpdateNeeded() {
*/ */
public void setUpdateNeeded(boolean updateNeeded) { public void setUpdateNeeded(boolean updateNeeded) {
if (updateNeeded) if (updateNeeded)
inCoreFlags |= UPDATE_NEEDED; inCoreFlags |= (byte) UPDATE_NEEDED;
else else
inCoreFlags &= ~UPDATE_NEEDED; inCoreFlags &= (byte) ~UPDATE_NEEDED;
} }
/** /**

View File

@ -661,7 +661,7 @@ private static boolean isTag(Ref ref) {
private int objectsBefore() { private int objectsBefore() {
int cnt = 0; int cnt = 0;
for (DfsPackFile p : packsBefore) for (DfsPackFile p : packsBefore)
cnt += p.getPackDescription().getObjectCount(); cnt += (int) p.getPackDescription().getObjectCount();
return cnt; return cnt;
} }

View File

@ -432,7 +432,7 @@ protected boolean onAppendBase(final int typeCode, final byte[] data,
buf[len++] = (byte) ((typeCode << 4) | (sz & 15)); buf[len++] = (byte) ((typeCode << 4) | (sz & 15));
sz >>>= 4; sz >>>= 4;
while (sz > 0) { while (sz > 0) {
buf[len - 1] |= 0x80; buf[len - 1] |= (byte) 0x80;
buf[len++] = (byte) (sz & 0x7f); buf[len++] = (byte) (sz & 0x7f);
sz >>>= 7; sz >>>= 7;
} }

View File

@ -356,7 +356,7 @@ protected boolean onAppendBase(final int typeCode, final byte[] data,
buf[len++] = (byte) ((typeCode << 4) | (sz & 15)); buf[len++] = (byte) ((typeCode << 4) | (sz & 15));
sz >>>= 4; sz >>>= 4;
while (sz > 0) { while (sz > 0) {
buf[len - 1] |= 0x80; buf[len - 1] |= (byte) 0x80;
buf[len++] = (byte) (sz & 0x7f); buf[len++] = (byte) (sz & 0x7f);
sz >>>= 7; sz >>>= 7;
} }

View File

@ -142,7 +142,7 @@ public static final byte[] apply(final byte[] base, final byte[] delta,
int c, shift = 0; int c, shift = 0;
do { do {
c = delta[deltaPtr++] & 0xff; c = delta[deltaPtr++] & 0xff;
baseLen |= ((long) (c & 0x7f)) << shift; baseLen |= (c & 0x7f) << shift;
shift += 7; shift += 7;
} while ((c & 0x80) != 0); } while ((c & 0x80) != 0);
if (base.length != baseLen) if (base.length != baseLen)
@ -155,7 +155,7 @@ public static final byte[] apply(final byte[] base, final byte[] delta,
shift = 0; shift = 0;
do { do {
c = delta[deltaPtr++] & 0xff; c = delta[deltaPtr++] & 0xff;
resLen |= ((long) (c & 0x7f)) << shift; resLen |= (c & 0x7f) << shift;
shift += 7; shift += 7;
} while ((c & 0x80) != 0); } while ((c & 0x80) != 0);

View File

@ -642,11 +642,12 @@ private boolean isEntryGitLink(AbstractTreeIterator ti) {
private void addConflict(String path, int stage) { private void addConflict(String path, int stage) {
StageState existingStageStates = conflicts.get(path); StageState existingStageStates = conflicts.get(path);
byte stageMask = 0; byte stageMask = 0;
if (existingStageStates != null) if (existingStageStates != null) {
stageMask |= existingStageStates.getStageMask(); stageMask |= (byte) existingStageStates.getStageMask();
}
// stage 1 (base) should be shifted 0 times // stage 1 (base) should be shifted 0 times
int shifts = stage - 1; int shifts = stage - 1;
stageMask |= (1 << shifts); stageMask |= (byte) (1 << shifts);
StageState stageState = StageState.fromMask(stageMask); StageState stageState = StageState.fromMask(stageMask);
conflicts.put(path, stageState); conflicts.put(path, stageState);
} }

View File

@ -95,7 +95,7 @@ public boolean matches(FooterKey key) {
for (int kPtr = 0; kPtr < len;) { for (int kPtr = 0; kPtr < len;) {
byte b = buffer[bPtr++]; byte b = buffer[bPtr++];
if ('A' <= b && b <= 'Z') if ('A' <= b && b <= 'Z')
b += 'a' - 'A'; b += (byte) ('a' - 'A');
if (b != kRaw[kPtr++]) if (b != kRaw[kPtr++])
return false; return false;
} }

View File

@ -113,7 +113,7 @@ public int getMarks(TreeWalk walk) throws MissingObjectException,
try { try {
boolean marked = filter.include(walk); boolean marked = filter.include(walk);
if (marked) if (marked)
marks |= (1L << index); marks |= (1 << index);
} catch (StopWalkException e) { } catch (StopWalkException e) {
// Don't check tree filter anymore, it will no longer // Don't check tree filter anymore, it will no longer
// match // match

View File

@ -58,7 +58,7 @@ java_package_configuration(
"-Xep:MissingFail:ERROR", "-Xep:MissingFail:ERROR",
"-Xep:MissingOverride:ERROR", "-Xep:MissingOverride:ERROR",
"-Xep:MutableConstantField:ERROR", "-Xep:MutableConstantField:ERROR",
"-Xep:NarrowingCompoundAssignment:WARN", "-Xep:NarrowingCompoundAssignment:ERROR",
"-Xep:NonAtomicVolatileUpdate:ERROR", "-Xep:NonAtomicVolatileUpdate:ERROR",
"-Xep:NonOverridingEquals:ERROR", "-Xep:NonOverridingEquals:ERROR",
"-Xep:NullableConstructor:ERROR", "-Xep:NullableConstructor:ERROR",