From bbfd9b0e5fc0160f5a1034ce23958a8040e88748 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Wed, 10 Jun 2015 13:59:48 -0700 Subject: [PATCH] Handle null in ProgressMonitor setters These commands' monitor fields can never be null unless someone passes null to setProgressMonitor. Anyone passing null probably meant to disable the ProgressMonitor, so do that (by falling back to NullProgressMonitor.INSTANCE) instead of saving a null and eventually producing NullPointerException. Change-Id: I63ad93ea8ad669fd333a5fd40880e7583ba24827 Signed-off-by: Jonathan Nieder --- org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 3 +++ org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java | 5 ++++- org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java | 3 +++ org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java | 3 +++ org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java | 3 +++ org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java | 3 +++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index cd0bf33ea..2b800e6c9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -432,6 +432,9 @@ public class CloneCommand extends TransportCommand { * @return {@code this} */ public CloneCommand setProgressMonitor(ProgressMonitor monitor) { + if (monitor == null) { + monitor = NullProgressMonitor.INSTANCE; + } this.monitor = monitor; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java index 527daef81..3e3a7a89c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DiffCommand.java @@ -268,7 +268,10 @@ public class DiffCommand extends GitCommand> { * @return this instance */ public DiffCommand setProgressMonitor(ProgressMonitor monitor) { + if (monitor == null) { + monitor = NullProgressMonitor.INSTANCE; + } this.monitor = monitor; return this; } -} \ No newline at end of file +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java index 29d475a22..9620089b0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java @@ -244,6 +244,9 @@ public class FetchCommand extends TransportCommand { */ public FetchCommand setProgressMonitor(ProgressMonitor monitor) { checkCallable(); + if (monitor == null) { + monitor = NullProgressMonitor.INSTANCE; + } this.monitor = monitor; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java index 63de85c50..2783edd5d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java @@ -130,6 +130,9 @@ public class PullCommand extends TransportCommand { * @return this instance */ public PullCommand setProgressMonitor(ProgressMonitor monitor) { + if (monitor == null) { + monitor = NullProgressMonitor.INSTANCE; + } this.monitor = monitor; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java index 0e1ce5831..227e32236 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java @@ -257,6 +257,9 @@ public class PushCommand extends */ public PushCommand setProgressMonitor(ProgressMonitor monitor) { checkCallable(); + if (monitor == null) { + monitor = NullProgressMonitor.INSTANCE; + } this.monitor = monitor; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 7196a2f38..ff2900842 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -1493,6 +1493,9 @@ public class RebaseCommand extends GitCommand { * @return this instance */ public RebaseCommand setProgressMonitor(ProgressMonitor monitor) { + if (monitor == null) { + monitor = NullProgressMonitor.INSTANCE; + } this.monitor = monitor; return this; }