Skip to content

Commit

Permalink
Disallow conditional annotations and declarative filter annotations o…
Browse files Browse the repository at this point in the history
…n methods

Although we can make this work in the future, it involves a fair amount of work
for a very small gain, so let's make it explicit for now that this combination
is not allowed.

Follows up on: quarkusio#29118
  • Loading branch information
geoand committed Nov 23, 2022
1 parent de814ab commit 930744b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ public void handleCustomAnnotatedMethods(
List<FilterGeneration.GeneratedFilter> generatedFilters = FilterGeneration.generate(index,
Set.of(HTTP_SERVER_REQUEST, HTTP_SERVER_RESPONSE, ROUTING_CONTEXT), Set.of(Unremovable.class.getName()),
(methodInfo -> {
List<AnnotationInstance> methodAnnotations = methodInfo.annotations();
for (AnnotationInstance methodAnnotation : methodAnnotations) {
if (BuildTimeEnabledProcessor.BUILD_TIME_ENABLED_BEAN_ANNOTATIONS.contains(methodAnnotation.name())) {
throw new RuntimeException("The combination of '@" + methodAnnotation.name().withoutPackagePrefix()
+ "' and '@ServerRequestFilter' or '@ServerResponseFilter' is not allowed. Offending method is '"
+ methodInfo.name() + "' of class '" + methodInfo.declaringClass().name() + "'");
}
}

List<AnnotationInstance> classAnnotations = methodInfo.declaringClass().declaredAnnotations();
for (AnnotationInstance classAnnotation : classAnnotations) {
if (BuildTimeEnabledProcessor.BUILD_TIME_ENABLED_BEAN_ANNOTATIONS.contains(classAnnotation.name())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.quarkus.resteasy.reactive.server.test.customproviders;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.function.Supplier;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.UriInfo;

import org.jboss.resteasy.reactive.server.ServerRequestFilter;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.profile.IfBuildProfile;
import io.quarkus.test.QuarkusUnitTest;

public class InvalidConditionalBeanFiltersTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(TestResource.class, Filters.class);
}
}).assertException(t -> {
String message = t.getMessage();
assertTrue(message.contains("@IfBuildProfile"));
assertTrue(message.contains("request"));
assertTrue(message.contains(InvalidConditionalBeanFiltersTest.Filters.class.getName()));
});

@Test
public void test() {
fail("Should never have been called");
}

@Path("test")
public static class TestResource {

@GET
public String hello() {
return "hello";
}

}

public static class Filters {

@IfBuildProfile("test")
@ServerRequestFilter
public void request(UriInfo info) {

}

}
}

0 comments on commit 930744b

Please sign in to comment.