Skip to content

Commit 8c1b465

Browse files
committed
JAVA-2701: Add more defensive checks when looking for the driver version to avoid NullPointerException in cases where the driver has been re-packaged without a manifest.
1 parent fdef549 commit 8c1b465

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

driver-core/src/main/com/mongodb/connection/ClientMetadataHelper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ private static String getDriverVersion() {
114114
if (jarUrl != null) {
115115
JarURLConnection jarURLConnection = (JarURLConnection) jarUrl.openConnection();
116116
Manifest manifest = jarURLConnection.getManifest();
117-
String version = (String) manifest.getMainAttributes().get(new Attributes.Name("Build-Version"));
118-
if (version != null) {
119-
driverVersion = version;
117+
if (manifest != null) {
118+
Attributes mainAttributes = manifest.getMainAttributes();
119+
if (mainAttributes != null) {
120+
String version = (String) mainAttributes.get(new Attributes.Name("Build-Version"));
121+
if (version != null) {
122+
driverVersion = version;
123+
}
124+
}
120125
}
121126
}
122127
} catch (IOException e) {

0 commit comments

Comments
 (0)