Skip to content

Commit

Permalink
fix(framework): ReflectionSidecar error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Jul 17, 2024
1 parent 3805a7f commit 3bde09e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object>.
4003=Method '%s' annotated with @ParamsMap in class '%s' must have exactly one parameter of type Map<String, Object>.
4004=Parameter '%s' annotated with @ParamsMap in method '%s' in class '%s' is not of type Map<String, Object>.
Expand Down

0 comments on commit 3bde09e

Please sign in to comment.