Skip to content

Commit 5434ab7

Browse files
ujjboyralf0131
authored andcommitted
Fix npe when package is null. (#3557)
1 parent ade0cd7 commit 5434ab7

File tree

1 file changed

+12
-8
lines changed
  • dubbo-common/src/main/java/org/apache/dubbo/common

1 file changed

+12
-8
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/Version.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,18 @@ private static String getPrefixDigits(String v) {
144144
public static String getVersion(Class<?> cls, String defaultVersion) {
145145
try {
146146
// find version info from MANIFEST.MF first
147-
String version = cls.getPackage().getImplementationVersion();
148-
if (!StringUtils.isEmpty(version)) {
149-
return version;
150-
}
151-
152-
version = cls.getPackage().getSpecificationVersion();
153-
if (!StringUtils.isEmpty(version)) {
154-
return version;
147+
Package pkg = cls.getPackage();
148+
String version = null;
149+
if (pkg != null) {
150+
version = pkg.getImplementationVersion();
151+
if (!StringUtils.isEmpty(version)) {
152+
return version;
153+
}
154+
155+
version = pkg.getSpecificationVersion();
156+
if (!StringUtils.isEmpty(version)) {
157+
return version;
158+
}
155159
}
156160

157161
// guess version fro jar file name if nothing's found from MANIFEST.MF

0 commit comments

Comments
 (0)