From 391c7a25fa8d247f9f6087f9f19ee330540ad602 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Sat, 9 Mar 2019 12:37:10 +0100 Subject: [PATCH] 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 --- org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java index 764f89015..0e96138c0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java +++ b/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 {