Source:
<code>public void run() { log.info("Resolving job specification"); final ObjectMapper prettyJsonMapper = GenieObjectMapper.getMapper() .copy() .enable(SerializationFeature.INDENT_OUTPUT); final JobSpecification spec; final String specId = resolveJobSpecCommandArguments.getSpecificationId(); if (!StringUtils.isBlank(specId)) { try { spec = agentJobSpecificationService.getJobSpecification(specId); } catch (final JobSpecificationResolutionException e) { throw new RuntimeException("Failed to get spec: " + specId, e); } } else { final AgentJobRequest agentJobRequest = jobRequestConverter.agentJobRequestArgsToDTO(resolveJobSpecCommandArguments.getJobRequestArguments()); if (!resolveJobSpecCommandArguments.isPrintRequestDisabled()) { try { System.out.println(prettyJsonMapper.writeValueAsString(agentJobRequest)); } catch (final JsonProcessingException e) { throw new RuntimeException("Failed to map request to JSON", e); } } try { spec = agentJobSpecificationService.resolveJobSpecification(agentJobRequest); } catch (final JobSpecificationResolutionException e) { throw new RuntimeException("Failed to resolve job specification", e); } } final String specJsonString; try { specJsonString = prettyJsonMapper.writeValueAsString(spec); } catch (final JsonProcessingException e) { throw new RuntimeException("Failed to map specification to JSON", e); } System.out.println(specJsonString); <START> final File outputFile = resolveJobSpecCommandArguments.getOutputFile(); <END> if (outputFile != null) { try { Files.write( outputFile.toPath(), specJsonString.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW ); } catch (final IOException e) { throw new RuntimeException("Failed to write request to: " + outputFile.getAbsolutePath(), e); } } }</code><technical_language>cleaner getOutputFile return Optional do resolveJobSpecCommandArguments.getOutputFile().ifPresent({})... flows slightly (IMO) writing a variable checking for null in if block logic..</technical_language>

Target:
public void run() { log.info("Resolving job specification"); final ObjectMapper prettyJsonMapper = GenieObjectMapper.getMapper() .copy() .enable(SerializationFeature.INDENT_OUTPUT); final JobSpecification spec; final String specId = resolveJobSpecCommandArguments.getSpecificationId(); if (!StringUtils.isBlank(specId)) { try { spec = agentJobSpecificationService.getJobSpecification(specId); } catch (final JobSpecificationResolutionException e) { throw new RuntimeException("Failed to get spec: " + specId, e); } } else { final AgentJobRequest agentJobRequest; try { final ArgumentDelegates.JobRequestArguments jobArgs = resolveJobSpecCommandArguments.getJobRequestArguments(); agentJobRequest = jobRequestConverter.agentJobRequestArgsToDTO(jobArgs); } catch (final JobRequestConverter.ConversionException e) { throw new RuntimeException("Failed to construct job request from arguments", e); } if (!resolveJobSpecCommandArguments.isPrintRequestDisabled()) { try { System.out.println(prettyJsonMapper.writeValueAsString(agentJobRequest)); } catch (final JsonProcessingException e) { throw new RuntimeException("Failed to map request to JSON", e); } } try { spec = agentJobSpecificationService.resolveJobSpecification(agentJobRequest); } catch (final JobSpecificationResolutionException e) { throw new RuntimeException("Failed to resolve job specification", e); } } final String specJsonString; try { specJsonString = prettyJsonMapper.writeValueAsString(spec); } catch (final JsonProcessingException e) { throw new RuntimeException("Failed to map specification to JSON", e); } System.out.println(specJsonString); final File outputFile = resolveJobSpecCommandArguments.getOutputFile(); if (outputFile != null) { try { Files.write( outputFile.toPath(), specJsonString.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW ); } catch (final IOException e) { throw new RuntimeException("Failed to write request to: " + outputFile.getAbsolutePath(), e); } } }