Skip to content

MethodSetter setProperty failing with generic IllegalArgumentException #357

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions