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 <jrn@google.com>
This commit is contained in:
Jonathan Nieder 2015-06-10 13:59:48 -07:00
parent e70cf61eb6
commit bbfd9b0e5f
6 changed files with 19 additions and 1 deletions

View File

@ -432,6 +432,9 @@ public CloneCommand setBranch(String branch) {
* @return {@code this}
*/
public CloneCommand setProgressMonitor(ProgressMonitor monitor) {
if (monitor == null) {
monitor = NullProgressMonitor.INSTANCE;
}
this.monitor = monitor;
return this;
}

View File

@ -268,7 +268,10 @@ public DiffCommand setDestinationPrefix(String destinationPrefix) {
* @return this instance
*/
public DiffCommand setProgressMonitor(ProgressMonitor monitor) {
if (monitor == null) {
monitor = NullProgressMonitor.INSTANCE;
}
this.monitor = monitor;
return this;
}
}
}

View File

@ -244,6 +244,9 @@ public ProgressMonitor getProgressMonitor() {
*/
public FetchCommand setProgressMonitor(ProgressMonitor monitor) {
checkCallable();
if (monitor == null) {
monitor = NullProgressMonitor.INSTANCE;
}
this.monitor = monitor;
return this;
}

View File

@ -130,6 +130,9 @@ protected PullCommand(Repository repo) {
* @return this instance
*/
public PullCommand setProgressMonitor(ProgressMonitor monitor) {
if (monitor == null) {
monitor = NullProgressMonitor.INSTANCE;
}
this.monitor = monitor;
return this;
}

View File

@ -257,6 +257,9 @@ public ProgressMonitor getProgressMonitor() {
*/
public PushCommand setProgressMonitor(ProgressMonitor monitor) {
checkCallable();
if (monitor == null) {
monitor = NullProgressMonitor.INSTANCE;
}
this.monitor = monitor;
return this;
}

View File

@ -1493,6 +1493,9 @@ public RebaseCommand setOperation(Operation operation) {
* @return this instance
*/
public RebaseCommand setProgressMonitor(ProgressMonitor monitor) {
if (monitor == null) {
monitor = NullProgressMonitor.INSTANCE;
}
this.monitor = monitor;
return this;
}