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

HV does not validate NotNull constraint on rest resources #16454

Closed
Postremus opened this issue Apr 12, 2021 · 1 comment
Closed

HV does not validate NotNull constraint on rest resources #16454

Postremus opened this issue Apr 12, 2021 · 1 comment
Labels
kind/bug Something isn't working

Comments

@Postremus
Copy link
Member

Describe the bug

I have a resource defined like this:

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getHello(@NotNull @QueryParam("param") String param) {
        return param;
    }

In my tests, I do not fill this QueryParam, and would therefore expect to get a response code 400 for this rest call.
However, I do get an 204er, indicating that:

  • the method was executed
  • and the param was null (null is mapped to status code 204)

This happens with resteasy classic, as well as with resteasy reactive.

I also tested this with BeanParams and with MultipartFormData. In both cases I explicitly left a field as null, but I never got a 400 response code.

@NotBlank in place of the @NotNull constraints works as expected - 400 is returned as status code, with a violation.

Expected behavior

NotNull should behave like NotBlank
For example, In case of NotBlank following violation is returned - I would expect similar for NotNull.

{
    "title": "Constraint Violation",
    "status": 400,
    "violations": [
        {
            "field": "hello.arg0.text",
            "message": "must not be blank"
        }
    ]
}

NotNull should work on rest resources, since it is used as an example in the spec. https://jakarta.ee/specifications/restful-ws/3.0/jakarta-restful-ws-spec-3.0.html#validation

Actual behavior

Right now, no violation, and no 400 status code ist returned for @NotNull on QueryParam, BeanParam, and MultiPartForm, for resteasy classic and reactive.

To Reproduce

Steps to reproduce the behavior:

  1. Download the reproducer: rr-bean-validation.zip
  2. Execute the test class GreetingResourceTest. All of the tests expect status code 400, but 204 is returned.
  3. Now, replace every NotNull constraint with NotBlank
  4. Execute the tests again, they should all be green now.

Environment (please complete the following information):

Output of uname -a or ver

Linux martin 5.8.0-48-generic #54~20.04.1-Ubuntu SMP Sat Mar 20 13:40:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment Zulu15.28+13-CA (build 15.0.1+8)
OpenJDK 64-Bit Server VM Zulu15.28+13-CA (build 15.0.1+8, mixed mode, sharing)

Quarkus version or git rev

1.13.1.Final

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/martin/.sdkman/candidates/maven/current
Java version: 15.0.1, vendor: Azul Systems, Inc., runtime: /home/martin/.sdkman/candidates/java/15.0.1-zulu
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-48-generic", arch: "amd64", family: "unix"

@Postremus Postremus added the kind/bug Something isn't working label Apr 12, 2021
@Postremus Postremus changed the title HV does not validate notnull on rest resources HV does not validate NotNull constraint on rest resources Apr 12, 2021
@Postremus
Copy link
Member Author

I am closing this issue, Just noticed that I Imported import io.smallrye.common.constraint.NotNull; instead of the javax.validation one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant