|
1 | 1 | /* |
2 | | - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -45,23 +45,25 @@ public class SimpleAliasRegistry implements AliasRegistry { |
45 | 45 | public void registerAlias(String name, String alias) { |
46 | 46 | Assert.hasText(name, "'name' must not be empty"); |
47 | 47 | Assert.hasText(alias, "'alias' must not be empty"); |
48 | | - if (alias.equals(name)) { |
49 | | - this.aliasMap.remove(alias); |
50 | | - } |
51 | | - else { |
52 | | - String registeredName = this.aliasMap.get(alias); |
53 | | - if (registeredName != null) { |
54 | | - if (registeredName.equals(name)) { |
55 | | - // An existing alias - no need to re-register |
56 | | - return; |
57 | | - } |
58 | | - if (!allowAliasOverriding()) { |
59 | | - throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" + |
60 | | - name + "': It is already registered for name '" + registeredName + "'."); |
| 48 | + synchronized (this.aliasMap) { |
| 49 | + if (alias.equals(name)) { |
| 50 | + this.aliasMap.remove(alias); |
| 51 | + } |
| 52 | + else { |
| 53 | + String registeredName = this.aliasMap.get(alias); |
| 54 | + if (registeredName != null) { |
| 55 | + if (registeredName.equals(name)) { |
| 56 | + // An existing alias - no need to re-register |
| 57 | + return; |
| 58 | + } |
| 59 | + if (!allowAliasOverriding()) { |
| 60 | + throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" + |
| 61 | + name + "': It is already registered for name '" + registeredName + "'."); |
| 62 | + } |
61 | 63 | } |
| 64 | + checkForAliasCircle(name, alias); |
| 65 | + this.aliasMap.put(alias, name); |
62 | 66 | } |
63 | | - checkForAliasCircle(name, alias); |
64 | | - this.aliasMap.put(alias, name); |
65 | 67 | } |
66 | 68 | } |
67 | 69 |
|
@@ -92,9 +94,11 @@ public boolean hasAlias(String name, String alias) { |
92 | 94 |
|
93 | 95 | @Override |
94 | 96 | public void removeAlias(String alias) { |
95 | | - String name = this.aliasMap.remove(alias); |
96 | | - if (name == null) { |
97 | | - throw new IllegalStateException("No alias '" + alias + "' registered"); |
| 97 | + synchronized (this.aliasMap) { |
| 98 | + String name = this.aliasMap.remove(alias); |
| 99 | + if (name == null) { |
| 100 | + throw new IllegalStateException("No alias '" + alias + "' registered"); |
| 101 | + } |
98 | 102 | } |
99 | 103 | } |
100 | 104 |
|
|
0 commit comments