From 5b39e5c1d02e011fdfdb9501472f4576d3aa2b5e Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Mon, 25 Feb 2019 14:42:30 +0800 Subject: [PATCH] Fix npe when package is null. --- .../java/org/apache/dubbo/common/Version.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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 6872e241f82..0ab48a6c4fc 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 @@ -144,14 +144,18 @@ private static String getPrefixDigits(String v) { public static String getVersion(Class cls, String defaultVersion) { try { // find version info from MANIFEST.MF first - String version = cls.getPackage().getImplementationVersion(); - if (!StringUtils.isEmpty(version)) { - return version; - } - - version = cls.getPackage().getSpecificationVersion(); - if (!StringUtils.isEmpty(version)) { - return version; + Package pkg = cls.getPackage(); + String version = null; + if (pkg != null) { + version = pkg.getImplementationVersion(); + if (!StringUtils.isEmpty(version)) { + return version; + } + + version = pkg.getSpecificationVersion(); + if (!StringUtils.isEmpty(version)) { + return version; + } } // guess version fro jar file name if nothing's found from MANIFEST.MF