Skip to content

Commit ab6919e

Browse files
committed
Retrieve MongoDB driver version reflectively.
To avoid inlining of the final/static version value, we're using reflection to look up the version value. Closes #4937
1 parent 921d035 commit ab6919e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/MongoClientVersion.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
*/
1616
package org.springframework.data.mongodb.util;
1717

18+
import java.lang.reflect.Field;
19+
1820
import org.springframework.data.util.Version;
1921
import org.springframework.lang.Nullable;
2022
import org.springframework.util.ClassUtils;
23+
import org.springframework.util.ReflectionUtils;
2124

2225
import com.mongodb.internal.build.MongoDriverVersion;
2326

@@ -96,8 +99,9 @@ private static Version getVersionFromPackage(ClassLoader classLoader) {
9699

97100
if (ClassUtils.isPresent("com.mongodb.internal.build.MongoDriverVersion", classLoader)) {
98101
try {
99-
return Version.parse(MongoDriverVersion.VERSION);
100-
} catch (IllegalArgumentException exception) {
102+
Field field = ReflectionUtils.findField(MongoDriverVersion.class, "VERSION");
103+
return field != null ? Version.parse("" + field.get(null)) : null;
104+
} catch (ReflectiveOperationException | IllegalArgumentException exception) {
101105
// well not much we can do, right?
102106
}
103107
}

0 commit comments

Comments
 (0)