diff --git a/framework/src/main/java/org/fulib/fx/controller/internal/ReflectionSidecar.java b/framework/src/main/java/org/fulib/fx/controller/internal/ReflectionSidecar.java index c609fd3..e7670f7 100644 --- a/framework/src/main/java/org/fulib/fx/controller/internal/ReflectionSidecar.java +++ b/framework/src/main/java/org/fulib/fx/controller/internal/ReflectionSidecar.java @@ -150,14 +150,17 @@ private void fillParametersIntoFields(@NotNull Object instance, @NotNull Map<@No // We cannot call the method on a non-existing property if (fieldValue == null) { - throw new RuntimeException(error(4001).formatted(param, field.getName(), instance.getClass().getName())); + throw new RuntimeException(error(4001).formatted(method, param, field.getName(), instance.getClass().getName())); } + final Class methodParamType = paramAnnotation.type(); try { - final Method methodName = field.getType().getMethod(method, paramAnnotation.type()); + final Method methodName = field.getType().getMethod(method, methodParamType); methodName.invoke(fieldValue, value); - } catch (ClassCastException | ReflectiveOperationException e) { - throw new RuntimeException(error(4007).formatted(param, field.getName(), instance.getClass().getName(), fieldType.getName(), value == null ? "null" : value.getClass().getName())); + } catch (IllegalArgumentException iae) { // parameter types don't match + throw new RuntimeException(error(4007).formatted(param, field.getName(), instance.getClass().getName(), methodParamType.getName(), value == null ? "null" : value.getClass().getName()), iae); + } catch (ReflectiveOperationException roe) { // method not found + throw new RuntimeException(error(4001).formatted(method, param, field.getName(), instance.getClass().getName()), roe); } } diff --git a/framework/src/main/resources/org/fulib/fx/lang/error.properties b/framework/src/main/resources/org/fulib/fx/lang/error.properties index 1fadcf0..9ec2b30 100644 --- a/framework/src/main/resources/org/fulib/fx/lang/error.properties +++ b/framework/src/main/resources/org/fulib/fx/lang/error.properties @@ -37,7 +37,7 @@ # Parameters 4000=Couldn't fill parameter '%s' into field '%s' in class '%s'. -4001=Couldn't call setter method with parameter '%s' for field '%s' in class '%s'. +4001=Couldn't call setter method '%s' with parameter '%s' for field '%s' in class '%s'. 4002=Field '%s' annotated with @ParamsMap in class '%s' is not of type Map. 4003=Method '%s' annotated with @ParamsMap in class '%s' must have exactly one parameter of type Map. 4004=Parameter '%s' annotated with @ParamsMap in method '%s' in class '%s' is not of type Map.