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

Bean introspection does not have annotation metadata for inherited props (when extending a class from another module) #6574

Closed
mitushy opened this issue Nov 25, 2021 · 3 comments · Fixed by #6588
Assignees
Labels
lang: groovy Issues or features specific to Groovy priority: high High priority type: bug Something isn't working
Milestone

Comments

@mitushy
Copy link

mitushy commented Nov 25, 2021

Expected Behavior

Creating an @Introspected class by extending another module's @Introspected class should have annotation metadata for all properties (own + inherited).

Actual Behaviour

Only local properties get returned when calling introspection.getIndexedProperty(AnnotationType)

This seems like a regression in 3.2.0. It was working fine in 3.1.3.

We found this when trying to update and tests started failing - we have controllers with @Valid @Body parameters which stopped validating properties inherited from micronaut-security's classes.

Interestingly, if the supertype is in the same module - it works fine.

Short gist below, but I've created a sample with a few tests trying to show our findings.

@Introspected
class ExtendingUsernamePasswordCredentials extends UsernamePasswordCredentials {
    @NotBlank
    @NotNull
    private String tenant
    // also inherits NotNull&NotBlank "password" and "username" fields from UsernamePasswordCredentials

    ExtendingUsernamePasswordCredentials(String tenant, String username, String password) {
        super(username, password)
        this.tenant = tenant
    }
    // .. getters, setters etc
}

@Validated
@Controller("/my"
class MyController {

    @Post("/login")
    MutableHttpResponse<?> login(@Valid @Body ExtendingUsernamePasswordCredentials tenantCreds) { /*..*/ }
}

Now, a request like:

POST http://localhost:8080/my/login
Content-Type: application/json

{
  "tenant": "tenant",
  "password": "pass"
}

will reach the controller, when it should have been rejected, because username is null.

Steps To Reproduce

  1. Use micronaut 3.2.0
  2. Create a subclass by extending from micronaut-security's UsernamePasswordCredentials
  3. Create a controller with @Valid @Body ExtendedCredentials
  4. Send a request with null username
  5. The controller will be executed with null binded, when this is not considered @Valid

Environment Information

  • OS: macOS 11.6.1
  • jdk: 20.3.0.r11-grl

Example Application

https://github.com/mitushy/micronaut-issue-6574

Version

3.2.0

@graemerocher graemerocher added type: bug Something isn't working priority: high High priority labels Nov 25, 2021
@graemerocher graemerocher added this to the 3.2.1 milestone Nov 25, 2021
@graemerocher
Copy link
Contributor

can you clarify which language you are using? Examples look like Groovy

@mitushy
Copy link
Author

mitushy commented Nov 25, 2021

Yes, sorry. The language is groovy. It may be groovy-specific, I haven't tried java.

@jameskleeh jameskleeh added the lang: groovy Issues or features specific to Groovy label Nov 29, 2021
@jameskleeh jameskleeh self-assigned this Nov 29, 2021
@jameskleeh
Copy link
Contributor

This is partially our issue but after fixing our end it is broken because of a Groovy bug

https://issues.apache.org/jira/browse/GROOVY-10398

@jameskleeh jameskleeh linked a pull request Nov 30, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: groovy Issues or features specific to Groovy priority: high High priority type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants