This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new f3fd88d6fc [type:fix] fix(plugin-base): avoid NPE in MetaDataCache
caching (#5985)
f3fd88d6fc is described below
commit f3fd88d6fc44ada465598efeca0a48943f078201
Author: yqw570994511 <[email protected]>
AuthorDate: Mon Mar 31 13:30:13 2025 +0800
[type:fix] fix(plugin-base): avoid NPE in MetaDataCache caching (#5985)
Prevent NullPointerException in concurrent update scenarios
Co-authored-by: yuqianwei <qq120405>
---
.../java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
index 799d9bf2a8..70d6725844 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/cache/MetaDataCache.java
@@ -71,12 +71,12 @@ public final class MetaDataCache {
*/
public void cache(final MetaData data) {
// clean old path data
- if (META_DATA_MAP.containsKey(data.getId())) {
+
Optional.ofNullable(META_DATA_MAP.get(data.getId())).ifPresent(oldMetaData -> {
// the update is also need to clean, but there is
// no way to distinguish between crate and update,
// so it is always clean
- clean(META_DATA_MAP.get(data.getId()).getPath());
- }
+ clean(oldMetaData.getPath());
+ });
META_DATA_MAP.put(data.getId(), data);
final String path = data.getPath();
clean(path);