Source:
<code>public StatusDTO status() { StatusCache statusCache = candlepinCache.getStatusCache(); StatusDTO cached = statusCache.getStatus(); if (cached != null) { return cached; } boolean good = true; try { rulesCurator.getUpdatedFromDB(); } catch (Exception e) { log.error("Error checking database connection", e); good = false; } CandlepinModeChange modeChange = modeManager.getLastCandlepinModeChange(); CandlepinModeChange.Mode mode = modeChange.getMode(); Iterator<CandlepinModeChange.Reason> reasonItr = modeChange.getReasons().iterator(); CandlepinModeChange.Reason modeChangeReason = reasonItr.hasNext() ? reasonItr.next() : null; if (mode != CandlepinModeChange.Mode.NORMAL) { good = false; } CandlepinCapabilities caps = CandlepinCapabilities.getCapabilities(); RulesSourceEnum rulesSource = jsProvider.getRulesSource(); StatusDTO status = new StatusDTO() .setResult(good) .setVersion(version) .setRelease(release) .setStandalone(standalone) .setRulesVersion(jsProvider.getRulesVersion()) .setRulesSource(rulesSource != null ? rulesSource.toString() : null) .setMode(mode != null ? mode.toString() : null) .setModeReason(modeChangeReason != null ? modeChangeReason.toString() : null) .setModeChangeTime(modeChange.getChangeTime()) .setManagerCapabilities(caps) .setTimeUTC(new Date()) <START> .setResource(resource) <END> .setAuthUrl(authUrl) .setRealm(realm); statusCache.setStatus(status); return status; }</code><technical_language>additions introduce interesting problem. In vast majority of expected cases, null, want necessary. In this case, I argue solution is add a subclass of StatusDTO provides additional fields. If operating keycloak enabled, subclass fields set. Otherwise, default "standard" StatusDTO provide fields. fields in DTO clearer. keycloakRealm some such</technical_language>

Target:
public StatusDTO status() { StatusCache statusCache = candlepinCache.getStatusCache(); StatusDTO cached = statusCache.getStatus(); if (cached != null) { return cached; } boolean good = true; try { rulesCurator.getUpdatedFromDB(); } catch (Exception e) { log.error("Error checking database connection", e); good = false; } CandlepinModeChange modeChange = modeManager.getLastCandlepinModeChange(); CandlepinModeChange.Mode mode = modeChange.getMode(); Iterator<CandlepinModeChange.Reason> reasonItr = modeChange.getReasons().iterator(); CandlepinModeChange.Reason modeChangeReason = reasonItr.hasNext() ? reasonItr.next() : null; if (mode != CandlepinModeChange.Mode.NORMAL) { good = false; } CandlepinCapabilities caps = CandlepinCapabilities.getCapabilities(); RulesSourceEnum rulesSource = jsProvider.getRulesSource(); StatusDTO status; if (keycloakEnabled) { AdapterConfig adapterConfig = keycloakConfig.getAdapterConfig(); status = new KeycloakStatusDTO() .setKeycloakResource(adapterConfig.getResource()) .setKeycloakAuthUrl(adapterConfig.getAuthServerUrl()) .setKeycloakRealm(adapterConfig.getRealm()); } else { status = new StatusDTO(); } status .setResult(good) .setVersion(version) .setRelease(release) .setStandalone(standalone) .setRulesVersion(jsProvider.getRulesVersion()) .setRulesSource(rulesSource != null ? rulesSource.toString() : null) .setMode(mode != null ? mode.toString() : null) .setModeReason(modeChangeReason != null ? modeChangeReason.toString() : null) .setModeChangeTime(modeChange.getChangeTime()) .setManagerCapabilities(caps) .setTimeUTC(new Date()); statusCache.setStatus(status); return status; }