Source:
<code>public CompletableFuture<RegistrationResponse> registerTaskManager( final String taskManagerRpcAddress, final UnresolvedTaskManagerLocation unresolvedTaskManagerLocation, final Time timeout) { final TaskManagerLocation taskManagerLocation; try { final boolean retrieveTaskManagerHostName = this.jobMasterConfiguration.getConfiguration() <START> .getBoolean(JobManagerOptions.RETRIEVE_TASK_MANAGER_HOSTNAME); <END> if (!retrieveTaskManagerHostName) { log.info("JobManager would not retrieve TaskManager's canonical hostname due to configuration."); } taskManagerLocation = TaskManagerLocation.fromUnresolvedLocation(unresolvedTaskManagerLocation, retrieveTaskManagerHostName); } catch (Throwable throwable) { final String errMsg = String.format( "Could not accept TaskManager registration. TaskManager address %s cannot be resolved. %s", unresolvedTaskManagerLocation.getExternalAddress(), throwable.getMessage()); log.error(errMsg); return CompletableFuture.completedFuture(new RegistrationResponse.Decline(errMsg)); } final ResourceID taskManagerId = taskManagerLocation.getResourceID(); if (registeredTaskManagers.containsKey(taskManagerId)) { final RegistrationResponse response = new JMTMRegistrationSuccess(resourceId); return CompletableFuture.completedFuture(response); } else { return getRpcService() .connect(taskManagerRpcAddress, TaskExecutorGateway.class) .handleAsync( (TaskExecutorGateway taskExecutorGateway, Throwable throwable) -> { if (throwable != null) { return new RegistrationResponse.Decline(throwable.getMessage()); } slotPool.registerTaskManager(taskManagerId); registeredTaskManagers.put(taskManagerId, Tuple2.of(taskManagerLocation, taskExecutorGateway)); taskManagerHeartbeatManager.monitorTarget(taskManagerId, new HeartbeatTarget<AllocatedSlotReport>() { @Override public void receiveHeartbeat(ResourceID resourceID, AllocatedSlotReport payload) { } @Override public void requestHeartbeat(ResourceID resourceID, AllocatedSlotReport allocatedSlotReport) { taskExecutorGateway.heartbeatFromJobManager(resourceID, allocatedSlotReport); } }); return new JMTMRegistrationSuccess(resourceId); }, getMainThreadExecutor()); } }</code><technical_language>I wondering sense move this local variable a field, do this lookup in constructor once</technical_language>

Target:
public CompletableFuture<RegistrationResponse> registerTaskManager( final String taskManagerRpcAddress, final UnresolvedTaskManagerLocation unresolvedTaskManagerLocation, final Time timeout) { final TaskManagerLocation taskManagerLocation; try { if (retrieveTaskManagerHostName) { taskManagerLocation = TaskManagerLocation.fromUnresolvedLocation( unresolvedTaskManagerLocation, ResolutionMode.RETRIEVE_HOST_NAME); } else { taskManagerLocation = TaskManagerLocation.fromUnresolvedLocation( unresolvedTaskManagerLocation, ResolutionMode.USE_IP_ONLY); } } catch (Throwable throwable) { final String errMsg = String.format( "Could not accept TaskManager registration. TaskManager address %s cannot be resolved. %s", unresolvedTaskManagerLocation.getExternalAddress(), throwable.getMessage()); log.error(errMsg); return CompletableFuture.completedFuture(new RegistrationResponse.Decline(errMsg)); } final ResourceID taskManagerId = taskManagerLocation.getResourceID(); if (registeredTaskManagers.containsKey(taskManagerId)) { final RegistrationResponse response = new JMTMRegistrationSuccess(resourceId); return CompletableFuture.completedFuture(response); } else { return getRpcService() .connect(taskManagerRpcAddress, TaskExecutorGateway.class) .handleAsync( (TaskExecutorGateway taskExecutorGateway, Throwable throwable) -> { if (throwable != null) { return new RegistrationResponse.Decline(throwable.getMessage()); } slotPool.registerTaskManager(taskManagerId); registeredTaskManagers.put(taskManagerId, Tuple2.of(taskManagerLocation, taskExecutorGateway)); taskManagerHeartbeatManager.monitorTarget(taskManagerId, new HeartbeatTarget<AllocatedSlotReport>() { @Override public void receiveHeartbeat(ResourceID resourceID, AllocatedSlotReport payload) { } @Override public void requestHeartbeat(ResourceID resourceID, AllocatedSlotReport allocatedSlotReport) { taskExecutorGateway.heartbeatFromJobManager(resourceID, allocatedSlotReport); } }); return new JMTMRegistrationSuccess(resourceId); }, getMainThreadExecutor()); } }