Skip to content

Polish: collapsible "if" statements should be merged #12236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ public class BackgroundPreinitializer

@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (event instanceof ApplicationStartingEvent) {
if (preinitializationStarted.compareAndSet(false, true)) {
performPreinitialization();
}
if (event instanceof ApplicationStartingEvent
&& preinitializationStarted.compareAndSet(false, true)) {
performPreinitialization();
}
if ((event instanceof ApplicationReadyEvent
|| event instanceof ApplicationFailedEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,12 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Builder message = ConditionMessage.forCondition("Embedded LDAP");
Environment environment = context.getEnvironment();
if (environment != null) {
if (!Binder.get(environment)
if (environment != null
&& !Binder.get(environment)
.bind("spring.ldap.embedded.base-dn", STRING_LIST)
.orElseGet(Collections::emptyList).isEmpty()) {
return ConditionOutcome
.match(message.because("Found base-dn property"));
}
return ConditionOutcome
.match(message.because("Found base-dn property"));
}
return ConditionOutcome.noMatch(message.because("No base-dn property found"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ protected void onApplicationEvent(ApplicationEvent event) {
logAutoConfigurationReport();
}
}
else if (event instanceof ApplicationFailedEvent) {
if (((ApplicationFailedEvent) event)
else if (event instanceof ApplicationFailedEvent
&& ((ApplicationFailedEvent) event)
.getApplicationContext() == initializerApplicationContext) {
logAutoConfigurationReport(true);
}
logAutoConfigurationReport(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,13 @@ protected AbstractSessionRepositoryValidator(SessionProperties sessionProperties
public void checkSessionRepository() {
StoreType storeType = this.sessionProperties.getStoreType();
if (storeType != StoreType.NONE
&& this.sessionRepositoryProvider.getIfAvailable() == null) {
if (storeType != null) {
throw new SessionRepositoryUnavailableException(
"No session repository could be auto-configured, check your "
+ "configuration (session store type is '"
+ storeType.name().toLowerCase(Locale.ENGLISH) + "')",
storeType);
}
&& this.sessionRepositoryProvider.getIfAvailable() == null
&& storeType != null) {
throw new SessionRepositoryUnavailableException(
"No session repository could be auto-configured, check your "
+ "configuration (session store type is '"
+ storeType.name().toLowerCase(Locale.ENGLISH) + "')",
storeType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,9 @@ private File getDefaultExtDirectory() {
String home = SystemPropertyUtils
.resolvePlaceholders("${spring.home:${SPRING_HOME:.}}");
File extDirectory = new File(new File(home, "lib"), "ext");
if (!extDirectory.isDirectory()) {
if (!extDirectory.mkdirs()) {
throw new IllegalStateException(
"Failed to create ext directory " + extDirectory);
}
if (!extDirectory.isDirectory() && !extDirectory.mkdirs()) {
throw new IllegalStateException(
"Failed to create ext directory " + extDirectory);
}
return extDirectory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ private static List<ExpressionStatement> getExpressionStatements(
private static ClosureExpression getClosure(String name,
MethodCallExpression expression) {
Expression method = expression.getMethod();
if (method instanceof ConstantExpression) {
if (name.equals(((ConstantExpression) method).getValue())) {
return (ClosureExpression) ((ArgumentListExpression) expression
.getArguments()).getExpression(0);
}
if (method instanceof ConstantExpression
&& name.equals(((ConstantExpression) method).getValue())) {
return (ClosureExpression) ((ArgumentListExpression) expression
.getArguments()).getExpression(0);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ private static List<String> getUrlsFromPrefixedWildcardPath(String path,
List<String> result = new ArrayList<>();
for (Resource resource : resources) {
if (resource.exists()) {
if (resource.getURI().getScheme().equals("file")) {
if (resource.getFile().isDirectory()) {
result.addAll(getChildFiles(resource));
continue;
}
if (resource.getURI().getScheme().equals("file")
&& resource.getFile().isDirectory()) {
result.addAll(getChildFiles(resource));
continue;
}
result.add(absolutePath(resource));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ private class TreeVisitorInvocationHandler implements InvocationHandler {
@SuppressWarnings("rawtypes")
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (method.getName().equals("visitClass")) {
if ((Integer) args[1] == 0) {
Iterable members = (Iterable) Tree.this.getClassTreeMembers
.invoke(args[0]);
for (Object member : members) {
if (member != null) {
Tree.this.acceptMethod.invoke(member, proxy,
((Integer) args[1]) + 1);
}
if (method.getName().equals("visitClass") && (Integer) args[1] == 0) {
Iterable members = (Iterable) Tree.this.getClassTreeMembers
.invoke(args[0]);
for (Object member : members) {
if (member != null) {
Tree.this.acceptMethod.invoke(member, proxy,
((Integer) args[1]) + 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,10 @@ static JarURLConnection get(URL url, JarFile jarFile) throws IOException {
index = separator + SEPARATOR.length();
}
JarEntryName jarEntryName = JarEntryName.get(spec, index);
if (Boolean.TRUE.equals(useFastExceptions.get())) {
if (!jarEntryName.isEmpty()
if (Boolean.TRUE.equals(useFastExceptions.get())
&& !jarEntryName.isEmpty()
&& !jarFile.containsEntry(jarEntryName.toString())) {
return NOT_FOUND_CONNECTION;
}
return NOT_FOUND_CONNECTION;
}
return new JarURLConnection(url, jarFile, jarEntryName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,11 @@ private int load(Object source) {
}

private int load(Class<?> source) {
if (isGroovyPresent()) {
if (isGroovyPresent() && GroovyBeanDefinitionSource.class.isAssignableFrom(source)) {
// Any GroovyLoaders added in beans{} DSL can contribute beans here
if (GroovyBeanDefinitionSource.class.isAssignableFrom(source)) {
GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source,
GroovyBeanDefinitionSource.class);
load(loader);
}
GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source,
GroovyBeanDefinitionSource.class);
load(loader);
}
if (isComponent(source)) {
this.annotatedReader.register(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ public void onApplicationEvent(ParentContextAvailableEvent event) {
}

private void maybeInstallListenerInParent(ConfigurableApplicationContext child) {
if (child == this.context) {
if (child.getParent() instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) child
.getParent();
parent.addApplicationListener(createContextCloserListener(child));
}
if (child == this.context
&& child.getParent() instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) child
.getParent();
parent.addApplicationListener(createContextCloserListener(child));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,18 @@ public void setTriggerEventType(

@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (this.triggerEventType.isInstance(event)) {
if (created.compareAndSet(false, true)) {
try {
writePidFile(event);
}
catch (Exception ex) {
String message = String.format("Cannot create pid file %s",
this.file);
if (failOnWriteError(event)) {
throw new IllegalStateException(message, ex);
}
logger.warn(message, ex);
if (this.triggerEventType.isInstance(event)
&& created.compareAndSet(false, true)) {
try {
writePidFile(event);
}
catch (Exception ex) {
String message = String.format("Cannot create pid file %s",
this.file);
if (failOnWriteError(event)) {
throw new IllegalStateException(message, ex);
}
logger.warn(message, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ protected String[] getSupportedTypes() {
@Override
public Configuration getConfiguration(LoggerContext loggerContext,
ConfigurationSource source) {
if (source != null && source != ConfigurationSource.NULL_SOURCE) {
if (LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) {
return new DefaultConfiguration();
}
if (source != null && source != ConfigurationSource.NULL_SOURCE
&& LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) {
return new DefaultConfiguration();
}
return null;
}
Expand Down