quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.85k stars 2.7k forks source link

Webfilter: Annotation and web.xml configs should be merged #11386

Open 38leinaD opened 4 years ago

38leinaD commented 4 years ago

Describe the bug I have a servlet filter without an explicit url mapping:

@WebFilter(filterName = "MyFilter", servletNames = "myservlet", asyncSupported = true)
public class MyFilter implements Filter {}

And i have a web.xml with a mapping:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="test"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  <display-name>test</display-name>
  <filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>org.acme.MyFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>MyFilter</filter-name>
    <servlet-name>faces</servlet-name>
    <url-pattern>/blah/*</url-pattern>
  </filter-mapping>
</web-app>

Expected behavior

Both configs should be merged; web.xml should have priority. And thus, the build should accept this filter and configure an url-pattern of "/blah/*"

This is how it works in many other servlet containers to my knowledge.

Actual behavior

The build fails with this exception because the @WebFilter annotation does not define an urlMapping:

Build failure: Build failed due to errors [error]: Build step io.quarkus.undertow.deployment.UndertowBuildStep#build threw an exception: java.lang.NullPointerException at io.quarkus.undertow.deployment.UndertowBuildStep.build(UndertowBuildStep.java:420) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:932) at io.quarkus.builder.BuildContext.run(BuildContext.java:277) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452) at java.lang.Thread.run(Thread.java:748) at org.jboss.threads.JBossThread.run(JBossThread.java:479)

Environment (please complete the following information):

16raghu commented 5 months ago

+1