aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java26
2 files changed, 28 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java
index 400a7dfe48..604cf1ee16 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java
@@ -43,6 +43,8 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.lib.Constants.checkNotNull;
+
import java.io.File;
import java.io.IOException;
@@ -220,9 +222,7 @@ public class Git implements AutoCloseable {
}
Git(Repository repo, boolean closeRepo) {
- if (repo == null)
- throw new NullPointerException();
- this.repo = repo;
+ this.repo = checkNotNull(repo);
this.closeRepo = closeRepo;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
index 4c55196961..e724c1525c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
@@ -58,7 +58,7 @@ import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.util.MutableInteger;
/**
- * Misc. constants used throughout JGit.
+ * Misc. constants and helpers used throughout JGit.
*/
@SuppressWarnings("nls")
public final class Constants {
@@ -466,6 +466,30 @@ public final class Constants {
public static final String ATTR_BUILTIN_BINARY_MERGER = "binary"; //$NON-NLS-1$
/**
+ * Null checker for a {@code @NonNull} parameter.
+ *
+ * <p>This is a briefer equivalent to
+ * <pre>
+ * if (arg == null) {
+ * throw new NullPointerException();
+ * }
+ * </pre>
+ * with the added benefit that it does not trigger nullness warnings when
+ * {@code arg} is declared as {@code @NonNull}.
+ *
+ * @param arg a non-null object reference
+ * @return arg
+ * @throws NullPointerException if {@code arg} is null
+ * @since 5.4
+ */
+ public static <T> T checkNotNull(T arg) {
+ if (arg == null) {
+ throw new NullPointerException();
+ }
+ return arg;
+ }
+
+ /**
* Create a new digest function for objects.
*
* @return a new digest object.