Skip to content

[BUG] - Filter class generic type argument is not validated in Java (APT) #1483

Description

@ClearPlume

Jimmer Version

0.11.0

JDK Version

JDK 21

Database

N/A

OS

Windows

Expected behavior

The DTO compiler reports an error when the filter class does not match the target entity type.

Actual behavior

Compilation of the DTO succeeds. The error surfaces later from javac, in generated code:

BookDeepView.java:115: error: incompatible types: AuthorFilter cannot be converted to FieldFilter<BookTable>

Description

DtoGenerator (KSP) parses the generic argument of KFieldFilter and compares it against the target entity type, throwing DtoException on mismatch. The APT implementation constructs the same GenericParser against FieldFilter and discards the result. The check is missing on the Java side; the error only surfaces from javac, at a line in generated code.

Reproduction steps

dto

export org.babyfish.jimmer.sql.model.Author

import testpkg.configurations.AuthorFilter

BookWithFilter {
    !filter(AuthorFilter)
    books {
        authorFullNames
    }
}

entity

@Entity
public interface Author {
    @ManyToMany(mappedBy = "authors")
    List<Book> books();
}

@Entity
public interface Book {
    @ManyToMany
    @JoinTable(
            name = "BOOK_AUTHOR_MAPPING",
            joinColumnName = "BOOK_ID",
            inverseJoinColumnName = "AUTHOR_ID",
            deletedWhenEndpointIsLogicallyDeleted = true
    )
    List<Author> authors();

    @Formula(dependencies = {"authors.firstName", "authors.lastName"})
    default List<String> authorFullNames() {
        List<String> fullNames = new ArrayList<>(authors().size());
        for (Author author : authors()) {
            fullNames.add(author.firstName() + "-" + author.lastName());
        }
        return fullNames;
    }
}

filter

public class AuthorFilter implements FieldFilter<AuthorTable> {

    @Override
    public void apply(FieldFilterArgs<AuthorTable> args) {
        AuthorTable table = args.getTable();
        args
                .where(
                        Predicate.and(
                                table.firstName().ne("Alex"),
                                table.lastName().ne("Banks")
                        )
                )
                .orderBy(
                        table.firstName().asc(),
                        table.lastName().asc()
                );
    }
}

Generated SQL

No response

Relation Model

No response

Screenshots

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions