-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: validator ParanamerParameterNameProvider with inheritance
PostPosted: Fri May 02, 2014 10:35 am 
Newbie

Joined: Fri May 02, 2014 10:17 am
Posts: 3
Hello,

When using inheritance sometimes I'm getting "arg0" instead of the right name.

Code:
import org.hibernate.validator.parameternameprovider.ParanamerParameterNameProvider;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.constraints.NotNull;
import java.lang.reflect.Method;
import java.util.Set;

interface Service {
    void sayHello(@NotNull String world);
}
class ServiceImpl implements Service {
    @Override
    public void sayHello(String world) {}
}

public class Test {
    public static void main(String[] args) throws NoSuchMethodException {
        ValidatorFactory factory = Validation.byDefaultProvider()
                .configure()
                .parameterNameProvider(new ParanamerParameterNameProvider())
                .buildValidatorFactory();
        Validator validator = factory.getValidator();
        Service service = new ServiceImpl();
        Method sayHello = Service.class.getMethod("sayHello", String.class);
        Set<ConstraintViolation<Service>> violations = validator.forExecutables().validateParameters(service, sayHello, new Object[]{null});
        System.out.println("violations = " + violations.iterator().next().getPropertyPath());
    }
}

Code:
<dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.el</artifactId>
            <version>2.2.6</version>
        </dependency>

        <dependency>
            <groupId>com.thoughtworks.paranamer</groupId>
            <artifactId>paranamer</artifactId>
            <version>2.5.5</version>
        </dependency>
    </dependencies>

possible results:
violations = sayHello.world
violations = sayHello.arg0

I believe the arg0 is coming from implementation and If I put @NotNull in the interface and the implementation I'm getting "world" only.

In a project I'm working on, the object creation is handled by guice (google dependency injection framework) that creates a proxy (iirc) and in this case sometimes I'm getting "arg0".

Is this a bug that I should report?


Top
 Profile  
 
 Post subject: Re: validator ParanamerParameterNameProvider with inheritance
PostPosted: Tue May 06, 2014 11:00 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
If you say "sometimes", does this mean the issue once happens for a given method and another time it doesn't happen for the very same method? Or is this to say it happens for some methods but not for others?

If you have a test case which reproduces the issue and you attach it to a JIRA issue, I can take a look. It may very well be though that we can't do much if Paranamer isn't able to retrieve parameter names from your proxy classes. In this case you may consider to implement a custom parameter name provider which always uses the "highest" method in the hierarchy to retrieve a name.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: validator ParanamerParameterNameProvider with inheritance
PostPosted: Tue May 06, 2014 11:55 am 
Newbie

Joined: Fri May 02, 2014 10:17 am
Posts: 3
Hi Gunnar,

Running the program above results in different outputs for the same method. It's not deterministic.


Top
 Profile  
 
 Post subject: Re: validator ParanamerParameterNameProvider with inheritance
PostPosted: Tue May 06, 2014 12:15 pm 
Newbie

Joined: Fri May 02, 2014 10:17 am
Posts: 3
https://hibernate.atlassian.net/browse/HV-887

There a test with a custom Paranamer


Top
 Profile  
 
 Post subject: Re: validator ParanamerParameterNameProvider with inheritance
PostPosted: Fri May 09, 2014 5:45 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Thanks for opening the issue and providing that great test case. I believe I've found the cause (see my comment on the issue).

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.