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>
tags/v5.3.0.201903130848-r
Michael Keppler 5 years ago
parent
commit
391c7a25fa
1 changed files with 5 additions and 1 deletions
  1. 5
    1
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java

+ 5
- 1
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java View File

@@ -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