Skip to content
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

Make resolution algorithm of ConnectionDetailsFactory more explicit #39737

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -122,13 +122,30 @@ record Registration<S, D extends ConnectionDetails>(Class<S> sourceType, Class<D
@SuppressWarnings("unchecked")
private static <S, D extends ConnectionDetails> Registration<S, D> get(ConnectionDetailsFactory<S, D> factory) {
ResolvableType type = ResolvableType.forClass(ConnectionDetailsFactory.class, factory.getClass());
if (!type.hasUnresolvableGenerics()) {
Class<?>[] generics = type.resolveGenerics();
Class<?>[] generics = resolveGenerics(type);
if (generics != null) {
return new Registration<>((Class<S>) generics[0], (Class<D>) generics[1], factory);
}
return null;
}

/**
* Resolve the generics of the given {@link ResolvableType} or {@code null} if any
* of them cannot be resolved.
* @param type the type to inspect
* @return the resolved generics if they can be loaded from the classpath,
* {@code null} otherwise
*/
private static Class<?>[] resolveGenerics(ResolvableType type) {
Class<?>[] resolvedGenerics = type.resolveGenerics();
for (Class<?> genericRawType : resolvedGenerics) {
if (genericRawType == null) {
return null;
}
}
return resolvedGenerics;
}

}

}