Skip to content

Commit 007720d

Browse files
committed
Improve null-safety of module/spring-boot-tomcat
See gh-46926
1 parent dcd25ab commit 007720d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/metrics/TomcatMetricsBinder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public TomcatMetricsBinder(MeterRegistry meterRegistry, Iterable<Tag> tags) {
6161
public void onApplicationEvent(ApplicationStartedEvent event) {
6262
ApplicationContext applicationContext = event.getApplicationContext();
6363
Manager manager = findManager(applicationContext);
64-
this.tomcatMetrics = new TomcatMetrics(manager, this.tags);
65-
this.tomcatMetrics.bindTo(this.meterRegistry);
64+
TomcatMetrics tomcatMetrics = new TomcatMetrics(manager, this.tags);
65+
tomcatMetrics.bindTo(this.meterRegistry);
66+
this.tomcatMetrics = tomcatMetrics;
6667
}
6768

6869
private @Nullable Manager findManager(ApplicationContext applicationContext) {
@@ -89,8 +90,9 @@ public void onApplicationEvent(ApplicationStartedEvent event) {
8990

9091
@Override
9192
public void destroy() {
92-
if (this.tomcatMetrics != null) {
93-
this.tomcatMetrics.close();
93+
TomcatMetrics tomcatMetrics = this.tomcatMetrics;
94+
if (tomcatMetrics != null) {
95+
tomcatMetrics.close();
9496
}
9597
}
9698

module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/servlet/NestedJarResourceSet.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,20 @@ protected void closeJarFile() {
119119

120120
@Override
121121
protected boolean isMultiRelease() {
122-
if (this.multiRelease == null) {
122+
Boolean multiRelease = this.multiRelease;
123+
if (multiRelease == null) {
123124
synchronized (this.archiveLock) {
124-
if (this.multiRelease == null) {
125+
multiRelease = this.multiRelease;
126+
if (multiRelease == null) {
125127
// JarFile.isMultiRelease() is final so we must go to the manifest
126128
Manifest manifest = getManifest();
127129
Attributes attributes = (manifest != null) ? manifest.getMainAttributes() : null;
128-
this.multiRelease = (attributes != null) && attributes.containsKey(MULTI_RELEASE);
130+
multiRelease = (attributes != null) && attributes.containsKey(MULTI_RELEASE);
131+
this.multiRelease = multiRelease;
129132
}
130133
}
131134
}
132-
return this.multiRelease;
135+
return multiRelease;
133136
}
134137

135138
@Override

0 commit comments

Comments
 (0)