Source:
<code>private void onContainersOfResourceAllocated(Resource resource, List<Container> containers) { final List<TaskExecutorProcessSpec> pendingTaskExecutorProcessSpecs = taskExecutorProcessSpecContainerResourceAdapter.getTaskExecutorProcessSpec(resource, matchingStrategy).stream() .flatMap(spec -> Collections.nCopies(getNumRequestedNotAllocatedWorkersFor(spec), spec).stream()) .collect(Collectors.toList()); int numPending = pendingTaskExecutorProcessSpecs.size(); log.info("Received containers with resource {}, pending container requests.", containers.size(), resource, numPending); final Iterator<Container> containerIterator = containers.iterator(); final Iterator<TaskExecutorProcessSpec> pendingTaskExecutorProcessSpecIterator = pendingTaskExecutorProcessSpecs.iterator(); final Iterator<AMRMClient.ContainerRequest> pendingRequestsIterator = getPendingRequestsAndCheckConsistency(resource, pendingTaskExecutorProcessSpecs.size()).iterator(); int numAccepted = 0; while (containerIterator.hasNext() && pendingTaskExecutorProcessSpecIterator.hasNext()) { final TaskExecutorProcessSpec taskExecutorProcessSpec = pendingTaskExecutorProcessSpecIterator.next(); final Container container = containerIterator.next(); final AMRMClient.ContainerRequest pendingRequest = pendingRequestsIterator.next(); final ResourceID resourceId = getContainerResourceId(container); <START> final CompletableFuture<YarnWorkerNode> requestResourceFuture = requestResourceFutures.get(taskExecutorProcessSpec).remove(0); <END> if (requestResourceFutures.get(taskExecutorProcessSpec).isEmpty()) { requestResourceFutures.remove(taskExecutorProcessSpec); } startTaskExecutorInContainer(container, taskExecutorProcessSpec, resourceId, requestResourceFuture); removeContainerRequest(pendingRequest); numAccepted++; } numPending -= numAccepted; int numExcess = 0; while (containerIterator.hasNext()) { returnExcessContainer(containerIterator.next()); numExcess++; } log.info("Accepted requested containers, returned excess containers, pending container requests of resource {}.", numAccepted, numExcess, numPending, resource); }</code><technical_language>NPE throw if requestResourceFutures.get(taskExecutorProcessSpec) is null empty. I recognized this happen design, protect assertion a proper error message</technical_language>

Target:
private void onContainersOfResourceAllocated(Resource resource, List<Container> containers) { final List<TaskExecutorProcessSpec> pendingTaskExecutorProcessSpecs = taskExecutorProcessSpecContainerResourceAdapter.getTaskExecutorProcessSpec(resource, matchingStrategy).stream() .flatMap(spec -> Collections.nCopies(getNumRequestedNotAllocatedWorkersFor(spec), spec).stream()) .collect(Collectors.toList()); int numPending = pendingTaskExecutorProcessSpecs.size(); log.info("Received containers with resource {}, pending container requests.", containers.size(), resource, numPending); final Iterator<Container> containerIterator = containers.iterator(); final Iterator<TaskExecutorProcessSpec> pendingTaskExecutorProcessSpecIterator = pendingTaskExecutorProcessSpecs.iterator(); final Iterator<AMRMClient.ContainerRequest> pendingRequestsIterator = getPendingRequestsAndCheckConsistency(resource, pendingTaskExecutorProcessSpecs.size()).iterator(); int numAccepted = 0; while (containerIterator.hasNext() && pendingTaskExecutorProcessSpecIterator.hasNext()) { final TaskExecutorProcessSpec taskExecutorProcessSpec = pendingTaskExecutorProcessSpecIterator.next(); final Container container = containerIterator.next(); final AMRMClient.ContainerRequest pendingRequest = pendingRequestsIterator.next(); final ResourceID resourceId = getContainerResourceId(container); final CompletableFuture<YarnWorkerNode> requestResourceFuture = Preconditions.checkNotNull( Preconditions.checkNotNull( requestResourceFutures.get(taskExecutorProcessSpec), "The requestResourceFuture for TasExecutorProcessSpec %s should not be null.", taskExecutorProcessSpec).poll(), "The requestResourceFuture queue for TasExecutorProcessSpec %s should not be empty.", taskExecutorProcessSpec); if (requestResourceFutures.get(taskExecutorProcessSpec).isEmpty()) { requestResourceFutures.remove(taskExecutorProcessSpec); } startTaskExecutorInContainer(container, taskExecutorProcessSpec, resourceId, requestResourceFuture); removeContainerRequest(pendingRequest); numAccepted++; } numPending -= numAccepted; int numExcess = 0; while (containerIterator.hasNext()) { returnExcessContainer(containerIterator.next()); numExcess++; } log.info("Accepted requested containers, returned excess containers, pending container requests of resource {}.", numAccepted, numExcess, numPending, resource); }