Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring controller silently ignored if mapping is defined in interface and if there's an error in it #43704

Closed
zhangjiangqige opened this issue Oct 4, 2024 · 5 comments · Fixed by #44642
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Milestone

Comments

@zhangjiangqige
Copy link

zhangjiangqige commented Oct 4, 2024

Describe the bug

This is probably related to the Spring extension. The symptom is that Quarkus build succeeds when it should've failed when an interface defining a controller contains errors.

This issue makes it pretty tricky to migrate Spring applications as the generated artifact just silently doesn't include endpoints defined in such controller interfaces.

Expected behavior

Build should fail, printing the error causing building a controller interface to fail.

Actual behavior

Quarkus builds successfully without printing anything about errors when building the interface. The resulting artifact doesn't contain the endpoints defined in the controller interface either.

How to Reproduce?

As an exemple, say we have an interface:

@RestController
@RequestMapping("/greeting")
public interface GreetingInterface {
    @GetMapping("/ping")
    String ping();

    @PostMapping("/hello")
    String hello(@RequestParam(required = false) @QueryParam("dung") String params);
}

and a controller class implementing the above interface

@Component
public class GreetingController implements GreetingInterface {

    @Override
    public String ping() {
        return "pinged";
    }

    @Override
    public String hello(String params) {
        return params.toString();
    }
}

building this code is supposed to fail with error Cannot have more than one of @PathParam, @QueryParam, @HeaderParam, @FormParam, @CookieParam, @BeanParam, @Context on method java.lang.String hello(java.lang.String params)

(note that the error in the above example is for illustration purpose only; the real error we have is the one in #43705 )

but in reality it can build successfully, and the resulting artifact doesn't include both APIs

$ ./mvnw quarkus:dev
...

$ curl -X GET http://localhost:8080/greeting/ping

404 - Resource Not Found
------------------------

Additional endpoints
	- /q/arc
		- CDI Overview
	- /q/arc/beans
		- Active CDI Beans
	- /q/arc/observers
		- Active CDI Observers
	- /q/arc/removed-beans
		- Removed CDI Beans
	- /q/dev-ui
		- Dev UI

In comparison, if the controller is defined completely in a class like below rather than an interface, Quarkus does fail the build and prints error:

@RestController
@RequestMapping("/unbuildable")
public class UnbuildableController {
    @PostMapping("/hello")
    public String hello(@RequestParam(required = false) @QueryParam("dung") String params) {
        return params.toString();
    }
}
Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:3.15.1:build (default) on project spring-web-quickstart: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor#setupEndpoints threw an exception: java.lang.RuntimeException: java.lang.RuntimeException: Failed to process method 'org.acme.spring.web.UnbuildableController#hello'
	at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:333)
	at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.setupEndpoints(ResteasyReactiveProcessor.java:658)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
	at java.base/java.lang.Thread.run(Thread.java:840)
	at org.jboss.threads.JBossThread.run(JBossThread.java:483)
Caused by: java.lang.RuntimeException: Failed to process method 'org.acme.spring.web.UnbuildableController#hello'
	at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:781)
	at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:422)
	at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createEndpoints(EndpointIndexer.java:300)
	... 10 more
Caused by: java.lang.RuntimeException: Cannot have more than one of @PathParam, @QueryParam, @HeaderParam, @FormParam, @CookieParam, @BeanParam, @Context on method java.lang.String hello(java.lang.String params) on class org.acme.spring.web.UnbuildableController
	at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.extractParameterInfo(EndpointIndexer.java:1242)
	at org.jboss.resteasy.reactive.common.processor.EndpointIndexer.createResourceMethod(EndpointIndexer.java:599)
	... 12 more

Output of uname -a or ver

Linux 5.10.225

Output of java -version

openjdk version "17.0.9" 2023-10-17 OpenJDK Runtime Environment GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22) OpenJDK 64-Bit Server VM GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22, mixed mode, sharing)

Quarkus version or git rev

3.15.1

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)

Additional information

No response

@zhangjiangqige zhangjiangqige added the kind/bug Something isn't working label Oct 4, 2024
@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label Oct 4, 2024
Copy link

quarkus-bot bot commented Oct 4, 2024

/cc @geoand (spring)

@gsmet
Copy link
Member

gsmet commented Oct 7, 2024

/cc @aureamunoz

@gsmet
Copy link
Member

gsmet commented Oct 23, 2024

@aureamunoz any chance you could have a look at this one?

@aureamunoz
Copy link
Member

Yes, I will

aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Nov 22, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Nov 26, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Nov 27, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Nov 27, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Nov 28, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Nov 29, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 3, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 5, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 9, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 9, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 10, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 11, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 12, 2024
aureamunoz added a commit to aureamunoz/quarkus that referenced this issue Dec 12, 2024
@aureamunoz
Copy link
Member

aureamunoz commented Dec 17, 2024

This one is now fixed by #44642 @geoand @gsmet

@geoand geoand closed this as completed Dec 17, 2024
@geoand geoand added this to the 3.18 - main milestone Dec 17, 2024
carlesarnal pushed a commit to carlesarnal/quarkus that referenced this issue Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/spring Issues relating to the Spring integration kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants