Browse Source

Avoid NPE in ObjectId.isId()

That method can easily be invoked with a null argument (e.g.
isId(repo.getFullBranch()), therefore it should handle null arguments.

Change was suggested in https://git.eclipse.org/r/#/c/137918/, which
tried to fix the same in egit only.

Bug:544982
Change-Id: I32d1df6e9b2946ab324eda7008721159019316b3
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
stable-5.3
Michael Keppler 6 years ago committed by David Pursehouse
parent
commit
391c7a25fa
  1. 6
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java

6
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java

@ -49,6 +49,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.InvalidObjectIdException;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.RawParseUtils;
@ -86,7 +87,10 @@ public class ObjectId extends AnyObjectId implements Serializable {
* the string to test.
* @return true if the string can converted into an ObjectId.
*/
public static final boolean isId(String id) {
public static final boolean isId(@Nullable String id) {
if (id == null) {
return false;
}
if (id.length() != Constants.OBJECT_ID_STRING_LENGTH)
return false;
try {

Loading…
Cancel
Save