Skip to content

Commit 1f1a7e0

Browse files
author
Phillip Webb
committed
Polish
1 parent 0d5c30f commit 1f1a7e0

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.context.ConfigurableApplicationContext;
2727
import org.springframework.context.event.ContextClosedEvent;
2828
import org.springframework.core.Ordered;
29+
import org.springframework.util.ObjectUtils;
2930

3031
/**
3132
* Listener that closes the application context if its parent is closed. It listens for
@@ -77,6 +78,9 @@ protected ContextCloserListener createContextCloserListener(
7778
return new ContextCloserListener(child);
7879
}
7980

81+
/**
82+
* {@link ApplicationListener} to close the context.
83+
*/
8084
protected static class ContextCloserListener implements
8185
ApplicationListener<ContextClosedEvent> {
8286

@@ -99,31 +103,23 @@ public void onApplicationEvent(ContextClosedEvent event) {
99103

100104
@Override
101105
public int hashCode() {
102-
final int prime = 31;
103-
int result = 1;
104-
result = prime
105-
* result
106-
+ ((this.childContext.get() == null) ? 0 : this.childContext.get()
107-
.hashCode());
108-
return result;
106+
return ObjectUtils.nullSafeHashCode(this.childContext.get());
109107
}
110108

111109
@Override
112110
public boolean equals(Object obj) {
113-
if (this == obj)
111+
if (this == obj) {
114112
return true;
115-
if (obj == null)
116-
return false;
117-
if (getClass() != obj.getClass())
118-
return false;
119-
ContextCloserListener other = (ContextCloserListener) obj;
120-
if (this.childContext.get() == null) {
121-
if (other.childContext.get() != null)
122-
return false;
123113
}
124-
else if (!this.childContext.get().equals(other.childContext.get()))
114+
if (obj == null) {
125115
return false;
126-
return true;
116+
}
117+
if (obj instanceof ContextCloserListener) {
118+
ContextCloserListener other = (ContextCloserListener) obj;
119+
return ObjectUtils.nullSafeEquals(this.childContext.get(),
120+
other.childContext.get());
121+
}
122+
return super.equals(obj);
127123
}
128124

129125
}

spring-boot/src/main/java/org/springframework/boot/context/event/EventPublishingRunListener.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ public void contextLoaded(ConfigurableApplicationContext context) {
9090
@Override
9191
public void finished(ConfigurableApplicationContext context, Throwable exception) {
9292
if (exception != null) {
93-
publishEvent(new ApplicationFailedEvent(this.application, this.args, context,
94-
exception));
95-
}
96-
else {
93+
ApplicationFailedEvent event = new ApplicationFailedEvent(this.application,
94+
this.args, context, exception);
95+
publishEvent(event);
9796
}
9897
}
9998

spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
* Tests for {@link SpringApplication}.
8181
*
8282
* @author Phillip Webb
83+
* @author Dave Syer
8384
*/
8485
public class SpringApplicationTests {
8586

0 commit comments

Comments
 (0)