Skip to content

Dynamically load com.mongodb.internal.build.MongoDriverVersion.VERSION #4938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Vladimir Vishnevskii
* @since 1.7
*/
public class MongoClientVersion {
Expand Down Expand Up @@ -96,14 +97,20 @@ private static Version getVersionFromPackage(ClassLoader classLoader) {

if (ClassUtils.isPresent("com.mongodb.internal.build.MongoDriverVersion", classLoader)) {
try {
return Version.parse(MongoDriverVersion.VERSION);
return Version.parse(loadVersionFromMongoDriverVersion());
} catch (IllegalArgumentException exception) {
// well not much we can do, right?
}
}
return null;
}

@Nullable
private static String loadVersionFromMongoDriverVersion() {
Field versionField = ReflectionUtils.findField(MongoDriverVersion.class, "VERSION");
return (String) ReflectionUtils.getField(versionField, null);
}

private static Version guessDriverVersionFromClassPath(ClassLoader classLoader) {

if (ClassUtils.isPresent("com.mongodb.internal.connection.StreamFactoryFactory", classLoader)) {
Expand Down