[3.0.x] Fix ClassCastException when using @With Java annotation#13282
Merged
Conversation
ClassCastException when using @With Java Annotation
ClassCastException when using @With Java Annotation ClassCastException when using @With Java annotation
ClassCastException when using @With Java annotationClassCastException when using @With Java annotation
Member
Author
|
So I had a look again. I am very sure this "fix" is correct. More explanation with this example: import play.mvc.*;
import java.util.concurrent.CompletionStage;
public final class AnnotationAction extends play.mvc.Action.Simple {
@Override
public CompletionStage<Result> call(Http.Request request) {
// Both of these line give a ClassCastException currently.
// After this PR it will be a NullPointerException
// So nothing really changes, but the exception is more accurate
configuration.getClass();
configuration.toString();
// The only thing that changes is that after this PR we can at least check
// for null (null = @With was used), but before this PR it was always "not null"
if(configuration == null) {
// @With was used - impossible to find out before
}
return delegate.call(request);
}
} @With(AnnotationAction.class)
public Result myAction { ... } |
Member
Author
|
@Mergifyio backport 2.9.x main |
Contributor
✅ Backports have been createdDetails
|
This was referenced May 22, 2025
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
See
This does not fix the problem but at least avoids the
ClassCastExceptionWhen using
@Withdirectly on an action method, there simply is no configuration.Even the "Simple Action" that is used in the docs when using
@Withmake that clear and usesVoidplayframework/core/play/src/main/java/play/mvc/Action.java
Lines 50 to 51 in cf19f57
However, what the author in #13281 tries, even fails with a
ClassCastExceptionwhen usingAction.Simplebecause alsoVoidcan not be cast to the desired type.