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

Deep nesting: Bug or misunderstanding? #60

Closed
henriquephil opened this issue Mar 2, 2020 · 2 comments · Fixed by #123
Closed

Deep nesting: Bug or misunderstanding? #60

henriquephil opened this issue Mar 2, 2020 · 2 comments · Fixed by #123
Labels
bug Something isn't working

Comments

@henriquephil
Copy link

So... I guess i found something wrong with nested nestIfPresent
I'm using version 0.4.0

Should the code below throw an exception or not?
In this test, there is a violation in the second validation

public class Main {
    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        Validator<Bar> barValidator = ValidatorBuilder.<Bar>of()
                .constraint(Bar::getValue, "name", Constraint::notNull)
                .build();
        Validator<Foo> fooValidator = ValidatorBuilder.<Foo>of()
                .nestIfPresent(Foo::getBar, "bar", barValidator)
                .build();
        Validator<Root> rootValidator = ValidatorBuilder.<Root>of()
                .nest(Root::getFoo, "foo", fooValidator)
                .build();

        // data
        Foo foo = new Foo(null);
        Root root = new Root(foo);

        // Working as expected
        ConstraintViolations fooViolations = fooValidator.validate(foo);
        if (!fooViolations.isEmpty()) throw new RuntimeException("no exceptions expected here");

        // Unexpected violation
        ConstraintViolations rootViolations = rootValidator.validate(root);
        if (!rootViolations.isEmpty()) throw new RuntimeException("neither here");
    }

    private class Root {
        private Foo foo;

        private Root(Foo foo) {
            this.foo = foo;
        }

        public Foo getFoo() {
            return foo;
        }
    }

    private class Foo {
        private Bar bar;

        private Foo(Bar bar) {
            this.bar = bar;
        }

        public Bar getBar() {
            return bar;
        }
    }

    private class Bar {
        private String value;

        private Bar(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }
}

And something similar is happening with forEach as well, I just couldn't find exacly what. Yet.

Could it be a bug or did I miss something?

@henriquephil henriquephil changed the title Bug or misunderstanding? Deep nesting: Bug or misunderstanding? Mar 2, 2020
@making making added question Further information is requested bug Something isn't working and removed question Further information is requested labels Mar 4, 2020
@making
Copy link
Owner

making commented Mar 4, 2020

@henriquephil
Thanks for the feedback!
It looks like it's not working as expected. Let me check when I have time. I'm currently pretty busy.

@making
Copy link
Owner

making commented May 12, 2021

fixed via #120

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

Successfully merging a pull request may close this issue.

2 participants