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
AbstractArgumentFactory fails to match generic types in 2.25.0 #2026
Comments
This looks like an actual bug. We have tons of code that checks whether the arguments behave correctly, however there is no check that the factory actually matches an argument. This test should pass: --- a/core/src/test/java/org/jdbi/v3/core/argument/TestAbstractArgumentFactory.java
+++ b/core/src/test/java/org/jdbi/v3/core/argument/TestAbstractArgumentFactory.java
@@ -17,6 +17,8 @@ import java.lang.reflect.Type;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.Optional;
+import java.util.function.Function;
import org.jdbi.v3.core.config.ConfigRegistry;
import org.jdbi.v3.core.generic.GenericType;
@@ -140,4 +142,18 @@ public class TestAbstractArgumentFactory {
argument.apply(2, statement, ctx);
verify(statement).setNull(2, Types.VARCHAR);
}
+
+ static class StringBox extends Box<String> {
+ StringBox(String value) {
+ super(value);
+ }
+ }
+
+ @Test
+ public void testArgumentFactorySelection() {
+ ArgumentFactory.Preparable preparable = new BoxOfStringArgumentFactory();
+ Optional<Function<Object, Argument>> argument = preparable.prepare(StringBox.class , new ConfigRegistry());
+
+ assertThat(argument).isPresent();
+ }
} What the code does is assuming that the argument factory either wraps a class (then it tests for assignability) or "something else", then it checks for equality. The latter part is the problem. In this case, it wraps a ParameterizedType ( |
…matches. This fixes jdbi#2026
The AbstractArgumentFactory needs to be able to deal with supertypes when being parameterized with Non-Classes (e.g. parameterized types). We had no tests to actually try that. This fixes jdbi#2026.
The AbstractArgumentFactory needs to be able to deal with supertypes when being parameterized with Non-Classes (e.g. parameterized types). We had no tests to actually try that. This fixes jdbi#2026.
The AbstractArgumentFactory needs to be able to deal with supertypes when being parameterized with Non-Classes (e.g. parameterized types). We had no tests to actually try that. This fixes jdbi#2026.
The AbstractArgumentFactory needs to be able to deal with supertypes when being parameterized with Non-Classes (e.g. parameterized types). We had no tests to actually try that. This fixes jdbi#2026.
I am upgrading from jdbi 2.78 to 3.25.0, but it seems the new AbstractArgumentFactory no longer matches when provided with generic type.
I saw this ticket, but maybe it regressed again? #1914
Works in 2.78
Fails in jdbi 3.25.0
with the following error
The text was updated successfully, but these errors were encountered: