AbstractBinder's afterPropertiesSet() is now final

- subclasses should implement the new onInit() method instead of overriding
- avoids the potential for a NPE in case an overriding subclass did not call the superclass method
This commit is contained in:
Mark Fisher
2016-03-02 13:29:49 -05:00
parent 9f9bc66345
commit 2bc59a184a
4 changed files with 14 additions and 9 deletions

View File

@@ -325,7 +325,7 @@ public class KafkaMessageChannelBinder extends AbstractBinder<MessageChannel> {
}
@Override
public void afterPropertiesSet() throws Exception {
public void onInit() throws Exception {
// we instantiate the connection factory here due to https://jira.spring.io/browse/XD-2647
ZookeeperConfiguration configuration = new ZookeeperConfiguration(this.zookeeperConnect);
configuration.setBufferSize(socketBufferSize);
@@ -348,7 +348,6 @@ public class KafkaMessageChannelBinder extends AbstractBinder<MessageChannel> {
retryTemplate.setBackOffPolicy(backOffPolicy);
retryOperations = retryTemplate;
}
super.afterPropertiesSet();
}
/**

View File

@@ -393,8 +393,7 @@ public class RabbitMessageChannelBinder extends AbstractBinder<MessageChannel> {
}
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
public void onInit() {
if (this.clustered) {
Assert.state(this.addresses.length == this.adminAddresses.length
&& this.addresses.length == this.nodes.length,

View File

@@ -132,8 +132,7 @@ public class RedisMessageChannelBinder extends AbstractBinder<MessageChannel> {
}
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
public void onInit() {
this.errorAdapter.setIntegrationEvaluationContext(this.evaluationContext);
this.errorAdapter.setBeanFactory(getBeanFactory());
this.errorAdapter.afterPropertiesSet();

View File

@@ -317,13 +317,21 @@ public abstract class AbstractBinder<T> implements ApplicationContextAware, Init
this.defaultCompress = defaultCompress;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(this.applicationContext, "The 'applicationContext' property cannot be null");
public final void afterPropertiesSet() throws Exception {
Assert.notNull(this.applicationContext, "The 'applicationContext' property must not be null");
if (this.evaluationContext == null) {
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
onInit();
}
/**
* Subclasses may implement this method to perform any necessary initialization.
* It will be invoked from {@link #afterPropertiesSet()} which is itself {@code final}.
*/
protected void onInit() throws Exception {
// no-op default
}
@Override