PackFileSnapshot: Resolve warnings by using "equals" instead of "=="
Errorprone raises the following warning: "[ReferenceEquality] Comparison using reference equality instead of value equality" Added Equality#isSameInstance util method to be reused in similar cases. Change-Id: Ifc9885c9806dcafa1c5ee1351d3095bf1517dbf5
This commit is contained in:
parent
88d5f51e61
commit
4ac6e7b505
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
import org.eclipse.jgit.lib.AnyObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
import org.eclipse.jgit.util.Equality;
|
||||||
|
|
||||||
class PackFileSnapshot extends FileSnapshot {
|
class PackFileSnapshot extends FileSnapshot {
|
||||||
|
|
||||||
|
@ -61,7 +62,8 @@ public boolean isModified(File packFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isChecksumChanged(File packFile) {
|
boolean isChecksumChanged(File packFile) {
|
||||||
return wasChecksumChanged = checksum != MISSING_CHECKSUM
|
return wasChecksumChanged = !Equality.isSameInstance(checksum,
|
||||||
|
MISSING_CHECKSUM)
|
||||||
&& !checksum.equals(readChecksum(packFile));
|
&& !checksum.equals(readChecksum(packFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022, Fabio Ponciroli <ponch78@gmail.com> and others
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Distribution License v. 1.0 which is available at
|
||||||
|
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eclipse.jgit.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equality utilities.
|
||||||
|
*
|
||||||
|
* @since: 6.2
|
||||||
|
*/
|
||||||
|
public class Equality {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare by reference
|
||||||
|
*
|
||||||
|
* @param a
|
||||||
|
* First object to compare
|
||||||
|
* @param b
|
||||||
|
* Second object to compare
|
||||||
|
* @return {@code true} if the objects are identical, {@code false}
|
||||||
|
* otherwise
|
||||||
|
*
|
||||||
|
* @since 6.2
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("ReferenceEquality")
|
||||||
|
public static <T> boolean isSameInstance(T a, T b) {
|
||||||
|
return a == b;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue