Fix validation for ActionResult return types #496
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Validate the type parameter of
ActionResult
, notActionResult
itself. Also improve the build error message for cases where an Action method's return type is a custom typeref but the@Action
parameter doesn't specify areturnTyperef
attribute.Context:
For an Action method that has a custom typeref return type (e.g.
CustomLong
) yet doesn't indicate in the@Action
parameter that it has a typeref class (e.g.CustomLongRef.class
), the error will show up as the following:CustomLong
:com.linkedin.restli.server.ResourceConfigException: @Action method 'doAction' on class 'com.example.impl.ExampleResource' has an invalid return type 'com.example.CustomLong'. Expected a DataTemplate or a primitive
ActionResult<CustomLong>
: an unhandled reflection exception.After this change, the error message will be this for both
CustomLong
andActionResult<CustomLong>
:com.linkedin.restli.server.ResourceConfigException: @Action method 'doAction' on class 'com.example.impl.ExampleResource' has an invalid return type 'com.example.CustomLong'. Expected a DataTemplate or a primitive, or expected returnTyperef to be specified in the @Action annotation.
A couple notes:
getLogicalReturnClass(method)
was used instead of thereturnClass
parameter (which is more accurate because it also unwrapsActionResult
) on purpose, but usingreturnClass
would be accurate as it would make validation consistent between return typesT
andActionResult<T>
.ActionResult
from the set of acceptable Action return types (it shouldn't be there if we're checking the logical return type).