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

MethodSetter setProperty failing with generic IllegalArgumentException #357

Open
ghost opened this issue Sep 19, 2022 · 0 comments
Open

Comments

@ghost
Copy link

ghost commented Sep 19, 2022

The method simply propagates the exception without offering any feedback.

Scenario, you make an incorrect column mapping class, let's say that you use java.util.Instant instead of java.sql.timestamp. Everything else is correct, just a type mismatch.

Then you do a simple select

var queryFormat = "Select * from %s where %s = :value";
return connection.createQuery(String.format(queryFormat, tableName, columnName))
        .addParameter("value", value)
        .setColumnMappings(provideColumnMapping())
        .executeAndFetch(clazz); // the class containing the incorrect column type

This eventually goes to: org.sql2o.reflection.MethodSetter#setProperty(Object obj, Object value)

Here, the try catch only cares about IllegalAccessException and InvocationTargetException. The IllegalArgumentException (or any other exception) is ignored and I don't get any feedback on what failed. What class? What method? What type? No idea.

I would expect the following, at least:

...
catch (IllegalArgumentException e) {
    throw new Sql2oException("error while calling setter method with name " + method.getName() + " on class " + obj.getClass().toString(), e);
}

But honestly, I'd even go a step further and do this for any exception.

EDIT: Using latest version, 1.6.0

@ghost ghost changed the title MethodSetter setProperty failing with i MethodSetter setProperty failing with generic IllegalArgumentException Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants