question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResteasyCommonProcessor: NullPointerException in case of using default annotation values for `@Produces` or `@Consumes`

See original GitHub issue

Describe the bug Hello. I’m getting a NullPointerException if I try to run a test for a simple web service with @Produces or @Consumes annotations default values.

Here is an example of such method:

    @POST
    @Path("integration")
    @Consumes
    @Produces
    public Response createIntegration() {
        return WebServiceCommon.performRedirect(authService.createIntegration());
    }

And the class itself: https://github.com/HardNorth/service-merge-validate/blob/c8952c753a693f287ce9655a8e55f34af4ea72d3/src/main/java/net/hardnorth/github/merge/api/MergeValidateController.java

Expected behavior No exception. A test passes.

Actual behavior

java.lang.RuntimeException: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor#setupProviders threw an exception: java.lang.NullPointerException
	at io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.collectDeclaredProvidersForMethodAndMediaTypeAnnotation(ResteasyCommonProcessor.java:531)
	at io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.collectDeclaredProviders(ResteasyCommonProcessor.java:463)
	at io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.setupProviders(ResteasyCommonProcessor.java:222)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:972)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2415)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)

To Reproduce

It will be enough to write a test on the following method:

    @POST
    @Path("test")
    @Consumes
    @Produces
    public Response test() {
        return Response.status(200).entity("OK").build();
    }

The test:

@QuarkusTest
public class EndpointTest{
    @Test
    public void tesEndpoint() {
        given()
                .when().post("/test")
                .then()
                .statusCode(200)
                .body(is("OK"));
    }
}

Steps to reproduce the behavior:

  1. Just run the test above

Configuration Here is my pom.xml file: https://github.com/HardNorth/service-merge-validate/blob/620c7ab336081db67cf6eab89c976f626ec67516/pom.xml

I’m using quarkus version 1.11.0.Final, the latest one on the moment I created the bug.

Screenshots Well, OK 😃 image

Environment (please complete the following information):

  • Output of uname -a or ver: Microsoft Windows 10 Home - 10.0.19042 N/A Build 19042
  • Output of java -version: openjdk 11 2018-09-25 OpenJDK Runtime Environment 18.9 (build 11+28) OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
  • Quarkus version or git rev: 1.11.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: C:\Users\delgr.m2\wrapper\dists\apache-maven-3.6.3-bin\1iopthnavndlasol9gbrbg6bf2\apache-maven-3.6.3 Java version: 11, vendor: Oracle Corporation, runtime: c:\java\openjdk_11 Default locale: en_US, platform encoding: Cp1251 OS name: “windows 10”, version: “10.0”, arch: “amd64”, family: “windows”

Additional context Well, as far as I digged into the problem the most probable culprit is jandex since it looks like it returns an instance of AnnotationInstance class with null in AnnotationValue field. That’s definetely incorrect since Annotations can’t have null fields. But I do not have all the details how quarkus uses jandex to post a bug on it, so please re-route the issue if I’m right here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
geoandcommented, Jan 19, 2022

Thanks for the reproducer!

https://github.com/quarkusio/quarkus/pull/23019 takes care of it

0reactions
khoekcommented, Jan 19, 2022

To be clear, you totally fixed it for @Produces on resource methods themselves.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring boot @Value NullPointerException - Stack Overflow
@value will be invoked after the object is created. Since you are using the property inside the constructor hence it is not available....
Read more >
Writing REST Services with RESTEasy Reactive - Quarkus
You may annotate your endpoint class with the @Produces or @Consumes annotations, which allow you to specify one or more media types that...
Read more >
Java static code analysis: "NullPointerException" should not ...
"switch case" clauses should not have too many lines of code. Code Smell ... Default annotation parameter values should not be passed as...
Read more >
How to Avoid NullPointerException | Ji ZHANG's Blog
NullPointerException happens when you dereference a possible null object ... By default, Eclipse uses annotations under its own package, ...
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
Using synchronized on a null object; Throwing null from a method that throws an exception. NullPointerException Example. Here is an example of a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found