diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityManager.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityManager.java index f4ce027c915..39d9b189510 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityManager.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityManager.java @@ -27,7 +27,6 @@ import java.lang.reflect.WildcardType; import java.net.URL; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -42,7 +41,7 @@ import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_INTERRUPTED; public class SerializeSecurityManager { - private final Set allowedPrefix = new LinkedHashSet<>(); + private final Set allowedPrefix = new ConcurrentHashSet<>(); private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(SerializeSecurityManager.class); @@ -84,7 +83,7 @@ public SerializeSecurityManager(FrameworkModel frameworkModel) { } } - public void registerInterface(Class clazz) { + public synchronized void registerInterface(Class clazz) { Set> markedClass = new HashSet<>(); markedClass.add(clazz); @@ -213,16 +212,18 @@ protected void addToAllow(String className) { public void registerListener(AllowClassNotifyListener listener) { listeners.add(listener); - listener.notify(checkStatus, allowedPrefix); + listener.notify(checkStatus, getAllowedPrefix()); } private void notifyListeners() { for (AllowClassNotifyListener listener : listeners) { - listener.notify(checkStatus, allowedPrefix); + listener.notify(checkStatus, getAllowedPrefix()); } } protected Set getAllowedPrefix() { - return allowedPrefix; + Set set = new ConcurrentHashSet<>(); + set.addAll(allowedPrefix); + return set; } }