Browse Source

Improve null-safety of module/spring-boot-tomcat

See gh-46926
pull/46973/head
Moritz Halbritter 4 months ago
parent
commit
007720d28d
  1. 10
      module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/metrics/TomcatMetricsBinder.java
  2. 11
      module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/servlet/NestedJarResourceSet.java

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

@ -61,8 +61,9 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart @@ -61,8 +61,9 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart
public void onApplicationEvent(ApplicationStartedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
Manager manager = findManager(applicationContext);
this.tomcatMetrics = new TomcatMetrics(manager, this.tags);
this.tomcatMetrics.bindTo(this.meterRegistry);
TomcatMetrics tomcatMetrics = new TomcatMetrics(manager, this.tags);
tomcatMetrics.bindTo(this.meterRegistry);
this.tomcatMetrics = tomcatMetrics;
}
private @Nullable Manager findManager(ApplicationContext applicationContext) {
@ -89,8 +90,9 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart @@ -89,8 +90,9 @@ public class TomcatMetricsBinder implements ApplicationListener<ApplicationStart
@Override
public void destroy() {
if (this.tomcatMetrics != null) {
this.tomcatMetrics.close();
TomcatMetrics tomcatMetrics = this.tomcatMetrics;
if (tomcatMetrics != null) {
tomcatMetrics.close();
}
}

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

@ -119,17 +119,20 @@ class NestedJarResourceSet extends AbstractSingleArchiveResourceSet { @@ -119,17 +119,20 @@ class NestedJarResourceSet extends AbstractSingleArchiveResourceSet {
@Override
protected boolean isMultiRelease() {
if (this.multiRelease == null) {
Boolean multiRelease = this.multiRelease;
if (multiRelease == null) {
synchronized (this.archiveLock) {
if (this.multiRelease == null) {
multiRelease = this.multiRelease;
if (multiRelease == null) {
// JarFile.isMultiRelease() is final so we must go to the manifest
Manifest manifest = getManifest();
Attributes attributes = (manifest != null) ? manifest.getMainAttributes() : null;
this.multiRelease = (attributes != null) && attributes.containsKey(MULTI_RELEASE);
multiRelease = (attributes != null) && attributes.containsKey(MULTI_RELEASE);
this.multiRelease = multiRelease;
}
}
}
return this.multiRelease;
return multiRelease;
}
@Override

Loading…
Cancel
Save