Skip to content

Java parametrized annotation composition fails #13281

@alok1111

Description

@alok1111

Is there a way to execute actions in some order if one of them is parametrized (doesn't extend Action.Simple)?
I've tried to use @With like this:
Controller

    @With(AnnotationAction.class)
    public Result indexWith() {
        return ok();
    }

AnnotationAction

public final class AnnotationAction extends Action<Annotation> {

    private static final Logger.ALogger log = Logger.of(AnnotationAction.class);

    @Override
    public CompletionStage<Result> call(Request request) {
            log.info(String.valueOf(configuration.skip()));
            return delegate.call(request);
    }
}

Annotation

@With(AnnotationAction.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Annotation {
    boolean skip() default false;
}

After executing the request, I get the following error from AnnotationAction on the line where the configuration variable resides:

java.lang.ClassCastException: class jdk.proxy4.$Proxy24 cannot be cast to class controllers.Annotation (jdk.proxy4.$Proxy24 is in module jdk.proxy4 of loader play.runsupport.NamedURLClassLoader @462f781a; controllers.Annotation is in unnamed module of loader play.runsupport.DelegatedResourcesClassLoader @417ee5ee)
	at controllers.AnnotationAction.call(AnnotationAction.java:14)
	at play.core.j.JavaAction.$anonfun$apply$8(JavaAction.scala:192)
	at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:687)
	at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
	at play.core.j.ClassLoaderExecutionContext.$anonfun$execute$1(ClassLoaderExecutionContext.scala:64)
	at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:65)
	at play.core.j.ClassLoaderExecutionContext.execute(ClassLoaderExecutionContext.scala:59)
	at scala.concurrent.impl.Promise$Transformation.submitWithValue(Promise.scala:429)

I'm okay with using the default skip value.

Is there any workaround for that? May I create another Action that wraps the initial and apply(and optionally configure) the Annotation there?

The reproducer is in the annotations branch here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions