You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/11/25 06:20:20 UTC

[dubbo] 34/45: fix:修复拿 Version 时可能存在的 NPE 问题

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch release/3.0.14-rpccontext-bugfix
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit df25e5f62ddfb8c732f05404d36b79c5d692859e
Author: 未宇 <li...@alibaba-inc.com>
AuthorDate: Thu Jan 7 15:26:03 2021 +0800

    fix:修复拿 Version 时可能存在的 NPE 问题
---
 dubbo-common/src/main/java/org/apache/dubbo/common/Version.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
index b949e6d..ddbed77 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
@@ -181,7 +181,12 @@ public final class Version {
                 return defaultVersion;
             }
 
-            String file = codeSource.getLocation().getFile();
+            URL location = codeSource.getLocation();
+            if (location == null){
+                logger.info("No location for class " + cls.getName() + " when getVersion, use default version " + defaultVersion);
+                return defaultVersion;
+            }
+            String file =  location.getFile();
             if (!StringUtils.isEmpty(file) && file.endsWith(".jar")) {
                 version = getFromFile(file);
             }