|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -122,13 +122,30 @@ record Registration<S, D extends ConnectionDetails>(Class<S> sourceType, Class<D
|
122 | 122 | @SuppressWarnings("unchecked")
|
123 | 123 | private static <S, D extends ConnectionDetails> Registration<S, D> get(ConnectionDetailsFactory<S, D> factory) {
|
124 | 124 | ResolvableType type = ResolvableType.forClass(ConnectionDetailsFactory.class, factory.getClass());
|
125 |
| - if (!type.hasUnresolvableGenerics()) { |
126 |
| - Class<?>[] generics = type.resolveGenerics(); |
| 125 | + Class<?>[] generics = resolveGenerics(type); |
| 126 | + if (generics != null) { |
127 | 127 | return new Registration<>((Class<S>) generics[0], (Class<D>) generics[1], factory);
|
128 | 128 | }
|
129 | 129 | return null;
|
130 | 130 | }
|
131 | 131 |
|
| 132 | + /** |
| 133 | + * Resolve the generics of the given {@link ResolvableType} or {@code null} if any |
| 134 | + * of them cannot be resolved. |
| 135 | + * @param type the type to inspect |
| 136 | + * @return the resolved generics if they can be loaded from the classpath, |
| 137 | + * {@code null} otherwise |
| 138 | + */ |
| 139 | + private static Class<?>[] resolveGenerics(ResolvableType type) { |
| 140 | + Class<?>[] resolvedGenerics = type.resolveGenerics(); |
| 141 | + for (Class<?> genericRawType : resolvedGenerics) { |
| 142 | + if (genericRawType == null) { |
| 143 | + return null; |
| 144 | + } |
| 145 | + } |
| 146 | + return resolvedGenerics; |
| 147 | + } |
| 148 | + |
132 | 149 | }
|
133 | 150 |
|
134 | 151 | }
|
0 commit comments