SimpleAliasRegistry fully synchronizes registerAlias and removeAlias
Issue: SPR-16577
This commit is contained in:
parent
42b4f6e1ff
commit
1b1a69a144
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -45,23 +45,25 @@ public class SimpleAliasRegistry implements AliasRegistry {
|
|||
public void registerAlias(String name, String alias) {
|
||||
Assert.hasText(name, "'name' must not be empty");
|
||||
Assert.hasText(alias, "'alias' must not be empty");
|
||||
if (alias.equals(name)) {
|
||||
this.aliasMap.remove(alias);
|
||||
}
|
||||
else {
|
||||
String registeredName = this.aliasMap.get(alias);
|
||||
if (registeredName != null) {
|
||||
if (registeredName.equals(name)) {
|
||||
// An existing alias - no need to re-register
|
||||
return;
|
||||
}
|
||||
if (!allowAliasOverriding()) {
|
||||
throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" +
|
||||
name + "': It is already registered for name '" + registeredName + "'.");
|
||||
}
|
||||
synchronized (this.aliasMap) {
|
||||
if (alias.equals(name)) {
|
||||
this.aliasMap.remove(alias);
|
||||
}
|
||||
else {
|
||||
String registeredName = this.aliasMap.get(alias);
|
||||
if (registeredName != null) {
|
||||
if (registeredName.equals(name)) {
|
||||
// An existing alias - no need to re-register
|
||||
return;
|
||||
}
|
||||
if (!allowAliasOverriding()) {
|
||||
throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" +
|
||||
name + "': It is already registered for name '" + registeredName + "'.");
|
||||
}
|
||||
}
|
||||
checkForAliasCircle(name, alias);
|
||||
this.aliasMap.put(alias, name);
|
||||
}
|
||||
checkForAliasCircle(name, alias);
|
||||
this.aliasMap.put(alias, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,9 +94,11 @@ public class SimpleAliasRegistry implements AliasRegistry {
|
|||
|
||||
@Override
|
||||
public void removeAlias(String alias) {
|
||||
String name = this.aliasMap.remove(alias);
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("No alias '" + alias + "' registered");
|
||||
synchronized (this.aliasMap) {
|
||||
String name = this.aliasMap.remove(alias);
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("No alias '" + alias + "' registered");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue