INT-3632: Backport Double Check Locking Fix

JIRA: https://jira.spring.io/browse/INT-3632
This commit is contained in:
Gary Russell
2015-02-12 11:15:22 -05:00
parent 924e0b767a
commit 4ca9486384
2 changed files with 12 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,18 +37,19 @@ import org.springframework.util.PatternMatchUtils;
* to {@link MessageHandler}s mapped by their {@code endpoint beanName}.
*
* @author Artem Bilan
* @author Gary Russell
* @since 4.1
*/
@SuppressWarnings("serial")
class IdempotentReceiverAutoProxyCreator extends AbstractAutoProxyCreator {
private List<Map<String, String>> idempotentEndpointsMapping;
private volatile List<Map<String, String>> idempotentEndpointsMapping;
private Map<String, List<String>> idempotentEndpoints;
private volatile Map<String, List<String>> idempotentEndpoints; // double check locking requires volatile
public void setIdempotentEndpointsMapping(List<Map<String, String>> idempotentEndpointsMapping) {
Assert.notEmpty(idempotentEndpointsMapping);
this.idempotentEndpointsMapping = idempotentEndpointsMapping;
this.idempotentEndpointsMapping = idempotentEndpointsMapping;//NOSONAR (inconsistent sync)
}
@Override
@@ -82,7 +83,7 @@ class IdempotentReceiverAutoProxyCreator extends AbstractAutoProxyCreator {
}
private void initIdempotentEndpointsIfNecessary() {
if (this.idempotentEndpoints == null) {
if (this.idempotentEndpoints == null) {//NOSONAR (inconsistent sync)
synchronized (this) {
if (this.idempotentEndpoints == null) {
this.idempotentEndpoints = new LinkedHashMap<String, List<String>>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ import org.springframework.util.StringUtils;
*
* @author David Liu
* @author Artem Bilan
* @author Gary Russell
* since 4.1
*/
public abstract class AbstractMessageProducingHandler extends AbstractMessageHandler
@@ -48,9 +49,9 @@ public abstract class AbstractMessageProducingHandler extends AbstractMessageHan
protected final MessagingTemplate messagingTemplate = new MessagingTemplate();
private MessageChannel outputChannel;
private volatile MessageChannel outputChannel;
private String outputChannelName;
private volatile String outputChannelName;
/**
* Set the timeout for sending reply Messages.
@@ -67,7 +68,7 @@ public abstract class AbstractMessageProducingHandler extends AbstractMessageHan
public void setOutputChannelName(String outputChannelName) {
Assert.hasText(outputChannelName, "'outputChannelName' must not be empty");
this.outputChannelName = outputChannelName;
this.outputChannelName = outputChannelName;//NOSONAR (inconsistent sync)
}
/**
@@ -82,7 +83,7 @@ public abstract class AbstractMessageProducingHandler extends AbstractMessageHan
@Override
protected void onInit() throws Exception {
super.onInit();
Assert.state(!(this.outputChannelName != null && this.outputChannel != null),
Assert.state(!(this.outputChannelName != null && this.outputChannel != null),//NOSONAR (inconsistent sync)
"'outputChannelName' and 'outputChannel' are mutually exclusive.");
if (getBeanFactory() != null) {
this.messagingTemplate.setBeanFactory(getBeanFactory());