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

Incorrect minimum value comparison logic in Jakarta/Javax ValidationConstraintGenerator #1127

Open
Seol-JY opened this issue Dec 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Seol-JY
Copy link

Seol-JY commented Dec 20, 2024

Describe the bug

In JakartaValidationConstraintGenerator class (line 365), there appears to be a meaningless self-comparison operation:

negativeMin = negativeMin.min(negativeMin);

It appears this was intended to be:

negativeMin = negativeMin.min(decimalMin);

For what seems to be a mistake, I tried to verify with the following test case:

public static class A {
    public A() {}

    public A(BigDecimal value) {
        this.value = value;
    }

    @NotNull
    @Max(-49)
    @Min(-100)
    @DecimalMin("-49.9")
    private BigDecimal value;

    public BigDecimal getValue() {
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }
}

Expected the final negativeMin to be -100 which should cause validation errors, but the code runs without exceptions.

Your environment

  • version of Fixture Monkey: 1.1.5
  • version of Java: 17

The code contains a self-comparison operation in its minimum value calculation, yet the validation process operates as expected in test cases.

I would like to understand:
Whether this code represents an actual issue
If it is an issue, why the test case still functions correctly

@Seol-JY Seol-JY added the bug Something isn't working label Dec 20, 2024
@seongahjo
Copy link
Contributor

@Seol-JY
Hi!

Thank you for reporting an issue.

Whether this code represents an actual issue If it is an issue, why the test case still functions correctly

That's because Fixture Monkey has two logical flows to satisfy the validation. link

Although the first flow (JakartaValidationConstraintGenerator) made a mistake, the second flow takes care of the problem.

It seems you are interested in contributing, could you do a PR for this issue?

Thank you.

@Seol-JY Seol-JY changed the title Incorrect minimum value comparison logic in JakartaValidationConstraintGenerator Incorrect minimum value comparison logic in Jakarta/Javax ValidationConstraintGenerator Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants