Source:
<code><START> public String getRunId() { <END> DistributedLock runIdLock; String runId = null; try { runIdLock = coordinationUtils.getLock(CoordinationConstants.RUNID_LOCK_ID); clusterMembership = coordinationUtils.getClusterMembership(); if (runIdLock == null || metadataStore == null || clusterMembership == null) { throw new SamzaException("Failed to create utils for run id generation"); } } catch (Exception e) { LOG.warn(e.getMessage()); return null; } try { if (runIdLock.lock(CoordinationConstants.LOCK_TIMEOUT_MS, TimeUnit.MILLISECONDS)) { LOG.info("lock acquired for run.id generation by this processor"); clusterMembership.registerProcessor(); int numberOfActiveProcessors = clusterMembership.getNumberOfProcessors(); if (numberOfActiveProcessors == 0) { String msg = String.format("Processor failed to fetch number of processors for run.id generation"); throw new SamzaException(msg); } if (numberOfActiveProcessors == 1) { runId = String.valueOf(System.currentTimeMillis()) + "-" + UUID.randomUUID().toString().substring(0, 8); LOG.info("Writing the run id for this run as {}", runId); metadataStore.put(CoordinationConstants.RUNID_STORE_KEY, runId.getBytes("UTF-8")); } else { runId = new String(metadataStore.get(CoordinationConstants.RUNID_STORE_KEY)); LOG.info("Read the run id for this run as {}", runId); } } } catch (TimeoutException e) { String msg = String.format("Processor timed out waiting to acquire lock for run.id generation"); throw new SamzaException(msg, e); } catch (UnsupportedEncodingException e) { String msg = String.format("Processor could not serialize/deserialize string for run.id generation"); throw new SamzaException(msg, e); } finally { runIdLock.unlock(); } return runId; }</code><technical_language>change signature return Optional<String> instead? prefer return null callers expect deal potential NPE</technical_language>

Target:
public Optional<String> getRunId() { DistributedLock runIdLock; String runId = null; runIdLock = coordinationUtils.getLock(CoordinationConstants.RUNID_LOCK_ID); if (runIdLock == null) { throw new SamzaException("Failed to create utils for run id generation"); } try { if (runIdLock.lock(Duration.ofMillis(CoordinationConstants.LOCK_TIMEOUT_MS))) { LOG.info("lock acquired for run.id generation by this processor"); processorId = clusterMembership.registerProcessor(); int numberOfActiveProcessors = clusterMembership.getNumberOfProcessors(); if (numberOfActiveProcessors == 0) { String msg = String.format("Processor failed to fetch number of processors for run.id generation"); throw new SamzaException(msg); } if (numberOfActiveProcessors == 1) { runId = String.valueOf(System.currentTimeMillis()) + "-" + UUID.randomUUID().toString().substring(0, 8); LOG.info("Writing the run id for this run as {}", runId); metadataStore.put(CoordinationConstants.RUNID_STORE_KEY, runId.getBytes("UTF-8")); } else { runId = new String(metadataStore.get(CoordinationConstants.RUNID_STORE_KEY)); LOG.info("Read the run id for this run as {}", runId); } runIdLock.unlock(); } else { throw new SamzaException("Processor timed out waiting to acquire lock for run.id generation"); } } catch (UnsupportedEncodingException e) { throw new SamzaException("Processor could not serialize/deserialize string for run.id generation", e); } return Optional.ofNullable(runId); }