Source:
<code>public SingularityPendingRequestParent scheduleImmediately(SingularityUser user, String requestId, SingularityRunNowRequest runNowRequest, boolean minimalReturn) { final Optional<SingularityRunNowRequest> maybeRunNowRequest = Optional.fromNullable(runNowRequest); SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user); authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE); checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to run now (it must be manually unpaused first)", requestWithState.getRequest().getId()); Integer activeTasks = null; <START> Integer pendingTasks = null; <END> boolean isOneoffWithInstances = requestWithState.getRequest().isOneOff() && requestWithState.getRequest().getInstances().isPresent(); if (requestWithState.getRequest().isScheduled() || isOneoffWithInstances) { activeTasks = taskManager.getActiveTaskIdsForRequest(requestId).size(); } if (isOneoffWithInstances) { pendingTasks = taskManager.getPendingTaskIdsForRequest(requestId).size(); } final SingularityPendingRequest pendingRequest = validator.checkRunNowRequest( getAndCheckDeployId(requestId), user.getEmail(), requestWithState.getRequest(), maybeRunNowRequest, activeTasks, pendingTasks); SingularityCreateResult result = requestManager.addToPendingQueue(pendingRequest); checkConflict(result != SingularityCreateResult.EXISTED, "%s is already pending, please try again soon", requestId); if (minimalReturn) { return SingularityPendingRequestParent.minimalFromRequestWithState(requestWithState, pendingRequest); } else { return SingularityPendingRequestParent.fromSingularityRequestParent(fillEntireRequest(requestWithState), pendingRequest); } }</code><technical_language>I want default 0 instead of null avoid NPE's in checkRunNowRequest()</technical_language>

Target:
public SingularityPendingRequestParent scheduleImmediately(SingularityUser user, String requestId, SingularityRunNowRequest runNowRequest, boolean minimalReturn) { final Optional<SingularityRunNowRequest> maybeRunNowRequest = Optional.fromNullable(runNowRequest); SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user); authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE); checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to run now (it must be manually unpaused first)", requestWithState.getRequest().getId()); int activeTasks = 0; int pendingTasks = 0; boolean isOneoffWithInstances = requestWithState.getRequest().isOneOff() && requestWithState.getRequest().getInstances().isPresent(); if (requestWithState.getRequest().isScheduled() || isOneoffWithInstances) { activeTasks = taskManager.getActiveTaskIdsForRequest(requestId).size(); } if (isOneoffWithInstances) { pendingTasks = taskManager.getPendingTaskIdsForRequest(requestId).size(); } final SingularityPendingRequest pendingRequest = validator.checkRunNowRequest( getAndCheckDeployId(requestId), user.getEmail(), requestWithState.getRequest(), maybeRunNowRequest, activeTasks, pendingTasks); SingularityCreateResult result = requestManager.addToPendingQueue(pendingRequest); checkConflict(result != SingularityCreateResult.EXISTED, "%s is already pending, please try again soon", requestId); if (minimalReturn) { return SingularityPendingRequestParent.minimalFromRequestWithState(requestWithState, pendingRequest); } else { return SingularityPendingRequestParent.fromSingularityRequestParent(fillEntireRequest(requestWithState), pendingRequest); } }