From 13a7c9df4b9d02af70899b324c35015743419210 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 19 Jan 2018 22:17:09 +0900 Subject: [PATCH] Add missing null checks and volatile keyword Closes gh-11692 --- .../ApplicationContextServerWebExchangeMatcher.java | 10 ++++++---- .../servlet/ApplicationContextRequestMatcher.java | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java index 1b95e3d85a..2a951d693a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java @@ -43,9 +43,9 @@ public abstract class ApplicationContextServerWebExchangeMatcher private final Class contextClass; - private C context; + private volatile C context; - private Object contextLock = new Object(); + private final Object contextLock = new Object(); public ApplicationContextServerWebExchangeMatcher(Class contextClass) { Assert.notNull(contextClass, "Context class must not be null"); @@ -68,8 +68,10 @@ public abstract class ApplicationContextServerWebExchangeMatcher protected C getContext(ServerWebExchange exchange) { if (this.context == null) { synchronized (this.contextLock) { - this.context = createContext(exchange); - initialized(this.context); + if (this.context == null) { + this.context = createContext(exchange); + initialized(this.context); + } } } return this.context; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java index deeff4869f..6bb4e85f39 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java @@ -45,7 +45,7 @@ public abstract class ApplicationContextRequestMatcher implements RequestMatc private volatile C context; - private Object contextLock = new Object(); + private final Object contextLock = new Object(); public ApplicationContextRequestMatcher(Class contextClass) { Assert.notNull(contextClass, "Context class must not be null"); @@ -68,8 +68,10 @@ public abstract class ApplicationContextRequestMatcher implements RequestMatc private C getContext(HttpServletRequest request) { if (this.context == null) { synchronized (this.contextLock) { - this.context = createContext(request); - initialized(this.context); + if (this.context == null) { + this.context = createContext(request); + initialized(this.context); + } } } return this.context;