Skip to content

Commit b4d6806

Browse files
authored
Fix DefaultRequestMappingRegistry.exists NPE when not initialized (#14936)
1 parent 6ad5809 commit b4d6806

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public void unregister(Invoker<?> invoker) {
180180
if (tree == null) {
181181
return;
182182
}
183+
183184
lock.writeLock().lock();
184185
try {
185186
tree.remove(mapping -> mapping.meta.getInvoker() == invoker);
@@ -193,6 +194,7 @@ public void destroy() {
193194
if (tree == null) {
194195
return;
195196
}
197+
196198
lock.writeLock().lock();
197199
try {
198200
tree.clear();
@@ -202,6 +204,10 @@ public void destroy() {
202204
}
203205

204206
public HandlerMeta lookup(HttpRequest request) {
207+
if (tree == null) {
208+
return null;
209+
}
210+
205211
String stringPath = PathUtils.normalize(request.uri());
206212
request.setAttribute(RestConstants.PATH_ATTRIBUTE, stringPath);
207213
KeyString path = new KeyString(stringPath, restConfig.getCaseSensitiveMatchOrDefault());
@@ -365,6 +371,10 @@ private void handleNoMatch(HttpRequest request, List<RequestMapping> partialMatc
365371

366372
@Override
367373
public boolean exists(String stringPath, String method) {
374+
if (tree == null) {
375+
return false;
376+
}
377+
368378
KeyString path = new KeyString(stringPath, restConfig.getCaseSensitiveMatchOrDefault());
369379
if (tryExists(path, method)) {
370380
return true;

0 commit comments

Comments
 (0)