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

checking if beandescriptor is null #672

Merged
merged 3 commits into from
Jul 11, 2014
Merged

Conversation

asouza
Copy link
Contributor

@asouza asouza commented Jul 8, 2014

If the parameter does not have any constraint, the returned BeanDescriptor is null...

@Turini
Copy link
Member

Turini commented Jul 8, 2014

can you add an unit test catching this case?

@garcia-jj
Copy link
Member

This behavior is too strange. Javadocs are not clear if getConstraintsForClass returns null. But I think that not because this method returns the class descriptor, not method descriptor. So it's to strange to return null.

I did some tests and getConstraintsForClass never returns null. Look my code below:

    public void m0() { }

    public void m1(String name) { }

    public void m2(@NotNull String name) { }

    @Test
    public void foo() {
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        BeanDescriptor bean = validator.getConstraintsForClass(AppTest.class);
        System.out.println("bean " + bean);

        System.out.println("m0 " + bean.getConstraintsForMethod("m0"));
        System.out.println("m1 " + bean.getConstraintsForMethod("m1", String.class));
        System.out.println("m2 " + bean.getConstraintsForMethod("m2", String.class));
    }

Prints:

bean BeanDescriptorImpl{class='AppTest'}
m0 null
m1 null
m2 ExecutableDescriptorImpl{name='m2'}

For me, there are no problem with this null check, but I don't think that this scenario will happen.

@asouza
Copy link
Contributor Author

asouza commented Jul 10, 2014

You are right, Otavio... I could not reproduce this scenario in the unit tests... But when I run the integration tests in vraptor-test, the problem always happens :(. My guess is that a problem with proxies or any other thing that we are not being able to see.

@@ -94,6 +99,14 @@ public void shouldNotAcceptIfMethodHasConstraint() {
getMethodValidator().validate(new MethodReady(withoutConstraint), controller, methodInfo, validator);
verify(controller, never()).getController();
}

@Test
public void shouldNotAcceptIfMethodDoesNotHaveConstraingAndHasDomainObjectParameter() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Constraing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here c1bb8d5

@Turini
Copy link
Member

Turini commented Jul 10, 2014

I think its good to merge... this is a simple null check, if helps on plugin 👍

@garcia-jj
Copy link
Member

Yes, good to merge if this can help vraptor test. But be carefully because
null can mask another error in vraptor-test.

@garcia-jj
Copy link
Member

🐑

Turini added a commit that referenced this pull request Jul 11, 2014
@Turini Turini merged commit f887ec5 into master Jul 11, 2014
@Turini Turini deleted the MethodValidator-NullDescriptor branch July 11, 2014 14:11
@Turini
Copy link
Member

Turini commented Jul 11, 2014

merged thanks!

@garcia-jj
Copy link
Member

Unused import CdiProxies.

@Turini
Copy link
Member

Turini commented Jul 11, 2014

removed here b01599d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants