Skip to content

[type-safe property references] deal with multiple references at once #1860

Closed

Description

@martinlippert

In code like this:

List<Category> all = repository.findAll(Sort.by("name", "description"));

we have multiple (in this case two) references to properties. At the moment, there is a warning and a quick fix showing up for each individually, but if you apply one of the quick fixes, the code ends up being broken due to the mixture of type-safe and stringly references to properties. It would be better if the quick fix would turn both properties into the type-safe variant in one go. Therefore, there should probably also be just one warning that underlines both strings in one range.

Activity

  1. added this to the 5.2.0.RELEASE milestone on Mar 30, 2026
  2. added
    for: eclipse
    for: vscode
    on Mar 30, 2026
  3. martinlippert commented on Mar 31, 2026

    @martinlippert
    MemberAuthor

    I minor polish suggestion: if there are multiple references in the warning, it should be Non type-safe property references for domain type 'Category' (plural for reference)

    I also observe that the quick fix to fix all stringly references in the file to the type-safe variant doesn't cover all occurrences. I am using spring-data-examples/jdbc/basics/src/test/java/example/springdata/jdbc/queryQueryTests.java as the example.

    The warning in queryFilterWithStringPropertyPath doesn't have the quick fix for "all in file", whereas the quick fix in sortBySinglePropertyWithStringPropertyPath has the "all-in-file" quick fix, but executing that quick fix also doesn't cover the case in queryFilterWithStringPropertyPath. It looks like the "all-in-file" quick fix covers "all" the sorting related property references OR all the references in query criteria.

    We could either have the "all-in-file" quick fix really fixing all the stringly references or have the quick fix label expressing that only specific references are converted.

  4. BoykoAlex commented on Mar 31, 2026

    @BoykoAlex
    Contributor

    I'm aware of that and I wasn't sure what to do for those cases... The cases when domain type is not exact but a high probability guess I've decided not to fix... I don't know what is better just pick the most probable fix and attempt to fix all or leave those cases out..

  5. martinlippert commented on Mar 31, 2026

    @martinlippert
    MemberAuthor

    I'm aware of that and I wasn't sure what to do for those cases... The cases when domain type is not exact but a high probability guess I've decided not to fix... I don't know what is better just pick the most probable fix and attempt to fix all or leave those cases out..

    Not sure I understand that. In my case above, all the stringly property references are nicely identified and get the right quick fix, but the "fix all" quick fix seems to cover only a specific subset of the warnings (either those from queries or those from sorting)

  6. BoykoAlex commented on Mar 31, 2026

    @BoykoAlex
    Contributor

    You're right... It should have been an exact domain type match in queryFilterWithStringPropertyPath... I'll see why it isn't

  7. martinlippert commented on Mar 31, 2026

    @martinlippert
    MemberAuthor

    You're right... It should have been an exact domain type match in queryFilterWithStringPropertyPath... I'll see why it isn't

    I think the validation does all this correctly, the domain type match is exact and the quick fix works perfectly. As said above:

    The warning in queryFilterWithStringPropertyPath doesn't have the quick fix for "all in file", whereas the quick fix in sortBySinglePropertyWithStringPropertyPath has the "all-in-file" quick fix, but executing that quick fix also doesn't cover the case in queryFilterWithStringPropertyPath. It looks like the "all-in-file" quick fix covers "all" the sorting related property references OR all the references in query criteria.

  8. martinlippert commented on Apr 1, 2026

    @martinlippert
    MemberAuthor

    Looks awesome now, great work!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: eclipsefor: vscodetheme: spring-data-supporttheme: validationtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions