Skip to content

Commit

Permalink
Merge pull request dropwizard#4670 from rhowe/avoid-shadowing-fields
Browse files Browse the repository at this point in the history
Avoid shadowing class fields with local variables
  • Loading branch information
jplock authored Feb 1, 2022
2 parents afa7ecd + a4e573f commit 1227668
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ ConfigurationParsingException build(String path) {
}

if (hasSuggestions()) {
final List<String> suggestions = getSuggestions();
final List<String> suggestionList = getSuggestions();
sb.append(NEWLINE).append(" Did you mean?:").append(NEWLINE);
final Iterator<String> it = suggestions.iterator();
final Iterator<String> it = suggestionList.iterator();
int i = 0;
while (it.hasNext() && i < MAX_SUGGESTIONS) {
sb.append(" - ").append(it.next());
Expand All @@ -267,7 +267,7 @@ ConfigurationParsingException build(String path) {
}
}

final int total = suggestions.size();
final int total = suggestionList.size();
if (i < total) {
sb.append(" [").append(total - i).append(" more]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public boolean configure(FeatureContext context) {
ConstraintValidatorFactory constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory();
if (constraintValidatorFactory instanceof MutableValidatorFactory) {
MutableValidatorFactory mutableValidatorFactory = (MutableValidatorFactory) constraintValidatorFactory;
ConstraintValidatorFactory validatorFactory =
ConstraintValidatorFactory resourceContextValidatorFactory =
resourceContext.getResource(InjectingConstraintValidatorFactory.class);

mutableValidatorFactory.setValidatorFactory(validatorFactory);
mutableValidatorFactory.setValidatorFactory(resourceContextValidatorFactory);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,17 +883,15 @@ public void asSingleConnectionPool() {

@Override
public ManagedDataSource build(MetricRegistry metricRegistry, String name) {
final Properties properties = new Properties();
for (Map.Entry<String, String> property : this.properties.entrySet()) {
properties.setProperty(property.getKey(), property.getValue());
}
final Properties dbProperties = new Properties();
properties.forEach(dbProperties::setProperty);

final PoolProperties poolConfig = new PoolProperties();
poolConfig.setAbandonWhenPercentageFull(abandonWhenPercentageFull);
poolConfig.setAlternateUsernameAllowed(alternateUsernamesAllowed);
poolConfig.setCommitOnReturn(commitOnReturn);
poolConfig.setRollbackOnReturn(rollbackOnReturn);
poolConfig.setDbProperties(properties);
poolConfig.setDbProperties(dbProperties);
poolConfig.setDefaultAutoCommit(autoCommitByDefault);
poolConfig.setDefaultCatalog(defaultCatalog);
poolConfig.setDefaultReadOnly(readOnlyByDefault);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void configure(final LifecycleEnvironment lifecycle, final ServletEnviron
}

final MetricRegistry metrics = lifecycle.getMetricRegistry();
final HealthCheckRegistry healthChecks = health.healthChecks();
final HealthCheckRegistry envHealthChecks = health.healthChecks();

final String fullName = DEFAULT_BASE_NAME + "-" + name;
final List<HealthCheckConfiguration> healthCheckConfigs = getHealthCheckConfigurations();
Expand All @@ -181,15 +181,15 @@ public void configure(final LifecycleEnvironment lifecycle, final ServletEnviron
mapper);

// register listener for HealthCheckRegistry and setup validator to ensure correct config
healthChecks.addListener(healthCheckManager);
lifecycle.manage(new HealthCheckConfigValidator(healthCheckConfigs, healthChecks));
envHealthChecks.addListener(healthCheckManager);
lifecycle.manage(new HealthCheckConfigValidator(healthCheckConfigs, envHealthChecks));

// register shutdown handler with Jetty
final Duration shutdownWaitPeriod = getShutdownWaitPeriod();
if (isDelayedShutdownHandlerEnabled() && shutdownWaitPeriod.toMilliseconds() > 0) {
final Duration shutdownDelay = getShutdownWaitPeriod();
if (isDelayedShutdownHandlerEnabled() && shutdownDelay.toMilliseconds() > 0) {
final DelayedShutdownHandler shutdownHandler = new DelayedShutdownHandler(healthCheckManager);
shutdownHandler.register();
LOGGER.debug("Set up delayed shutdown with delay: {}", shutdownWaitPeriod);
LOGGER.debug("Set up delayed shutdown with delay: {}", shutdownDelay);
}

// Set the health state aggregator on the HealthEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public Handler[] getHandlers() {
@Override
protected void expandChildren(List<Handler> list, Class<?> byClass)
{
Handler[] handlers = getHandlers();
if (handlers != null) {
for (Handler h : handlers) {
Handler[] handlerArray = getHandlers();
if (handlerArray != null) {
for (Handler h : handlerArray) {
expandHandler(h, list, byClass);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,29 +716,29 @@ protected SslContextFactory configureSslContextFactory(SslContextFactory factory
factory.setKeyStorePath(keyStorePath);
}

final String keyStoreType = getKeyStoreType();
if (keyStoreType.startsWith("Windows-")) {
final String realKeyStoreType = getKeyStoreType();
if (realKeyStoreType.startsWith("Windows-")) {
try {
final KeyStore keyStore = KeyStore.getInstance(keyStoreType);
final KeyStore keyStore = KeyStore.getInstance(realKeyStoreType);

keyStore.load(null, null);
factory.setKeyStore(keyStore);
} catch (Exception e) {
throw new IllegalStateException("Windows key store not supported", e);
}
} else {
factory.setKeyStoreType(keyStoreType);
factory.setKeyStoreType(realKeyStoreType);
factory.setKeyStorePassword(keyStorePassword);
}

if (keyStoreProvider != null) {
factory.setKeyStoreProvider(keyStoreProvider);
}

final String trustStoreType = getTrustStoreType();
if (trustStoreType.startsWith("Windows-")) {
final String realTrustStoreType = getTrustStoreType();
if (realTrustStoreType.startsWith("Windows-")) {
try {
final KeyStore keyStore = KeyStore.getInstance(trustStoreType);
final KeyStore keyStore = KeyStore.getInstance(realTrustStoreType);

keyStore.load(null, null);
factory.setTrustStore(keyStore);
Expand All @@ -752,7 +752,7 @@ protected SslContextFactory configureSslContextFactory(SslContextFactory factory
if (trustStorePassword != null) {
factory.setTrustStorePassword(trustStorePassword);
}
factory.setTrustStoreType(trustStoreType);
factory.setTrustStoreType(realTrustStoreType);
}

if (trustStoreProvider != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public void stop() {
// mechanism built into logback, we wait for a short period of time before
// giving up that the appender will be completely flushed.
final Logger logger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
final Iterator<Appender<ILoggingEvent>> appenders = logger.iteratorForAppenders();
while (appenders.hasNext()) {
final Appender<ILoggingEvent> appender = appenders.next();
final Iterator<Appender<ILoggingEvent>> appenderIterator = logger.iteratorForAppenders();
while (appenderIterator.hasNext()) {
final Appender<ILoggingEvent> appender = appenderIterator.next();
if (appender instanceof AsyncAppenderBase) {
flushAppender((AsyncAppenderBase<?>) appender);
} else if (appender instanceof AsyncAppenderBaseProxy) {
Expand Down

0 comments on commit 1227668

Please sign in to comment.