-->
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.  [ 6 posts ] 
Author Message
 Post subject: Exception creating new custom constraint
PostPosted: Sun May 04, 2014 3:54 pm 
Newbie

Joined: Sun May 04, 2014 3:25 pm
Posts: 3
Hi,

We recently added a new custom constraint and it is working perfectly. We then added a second, similar custom constraint, but when we deploy, we get the following exception:


Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: CDI definition failure:Exception List with 1 exceptions:
Exception 0 :
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.validator.internal.util.ReflectionHelper.parametersResolveToSameTypes(ReflectionHelper.java:755)
at org.hibernate.validator.internal.util.ReflectionHelper.overrides(ReflectionHelper.java:726)
at org.hibernate.validator.internal.cdi.ValidationExtension.replaceWithOverriddenOrInterfaceMethod(ValidationExtension.java:389)
at org.hibernate.validator.internal.cdi.ValidationExtension.determineConstrainedMethod(ValidationExtension.java:214)
at org.hibernate.validator.internal.cdi.ValidationExtension.determineConstrainedCallables(ValidationExtension.java:201)
at org.hibernate.validator.internal.cdi.ValidationExtension.processAnnotatedType(ValidationExtension.java:181)
...
__________________

Here are the relevant pieces of code:

The Annotation:

Code:
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = {DatasetFieldValidator.class})
@Documented
public @interface ValidateDatasetField {

  String message() default "Required";

  Class<?>[] groups() default {};

  Class<? extends Payload>[] payload() default {};

}


The Validator
Code:
public class DatasetFieldValidator implements ConstraintValidator<ValidateDatasetField, DatasetField> {

    @Override
    public void initialize(ValidateDatasetField constraintAnnotation) {
    }

    @Override
    public boolean isValid(DatasetField value, ConstraintValidatorContext context) {

        ...

        return true;
    }

}



The entity to be validated:
Code:
@Entity
@ValidateDatasetField
public class DatasetField implements Serializable {



Like I said, when I look at the code of the the other validator, it looks very parallel and it works.

Any ideas?


Top
 Profile  
 
 Post subject: Re: Exception creating new custom constraint
PostPosted: Tue May 06, 2014 10:55 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

This looks like another manifestation of https://hibernate.atlassian.net/browse/HV-861. Would it be possible for you to add a minimal test case to this JIRA ticket which reproduces the issue? It has been reported before and so far we couldn't get to the exact cause.

Thanks,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Exception creating new custom constraint
PostPosted: Tue May 06, 2014 11:36 am 
Newbie

Joined: Sun May 04, 2014 3:25 pm
Posts: 3
Hi,

Thanks for responding. we have actually found a workaround for this and *think* we may know the cause.

(I've been meaning to reply to my original post, but am busy trying to get a beta release out the door - let me at least get a quick response in now).

In my sample code, I did not include the internals of the DatasetField.java class because I didn't realize they were relevant, but when I discussed with a friend of mine, we found that they in fact are. In our Datasetfield class we had two instances of overloaded methods.

___________________________________

ValidationExtension: determineConstrainedMethod: line 271:
List<Method> overriddenAndImplementedMethods = ClassHierarchyHelper.getAllMethods( type.getJavaClass() );


seems to look at all methods and not just overridden or implemented methods. So it appears the overrides method in ReflectionHelper (or ExecutableHelper) is getting called for the overloaded methods and that causes the issue.

Renaming the methods so that they are not overloaded resolved the issue.

Let me know if I can provide more info or help, but hopefully this is it! Now back to our beta...

Gustavo


Top
 Profile  
 
 Post subject: Re: Exception creating new custom constraint
PostPosted: Fri May 09, 2014 5:34 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Gustavo,

Thanks for reporting back on this. Can you share the exact signatures of the overloaded methods which cause the problem?

Thanks,

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Exception creating new custom constraint
PostPosted: Fri May 09, 2014 10:51 am 
Newbie

Joined: Sun May 04, 2014 3:25 pm
Posts: 3
Of course!

In both cases, there is a 3rd private method (called by the public methods), but with a different # of parameters. Below are both examples, after I un-overloaded names:


public static DatasetField createNewEmptyDatasetField(DatasetFieldType dsfType, DatasetVersion dsv) {
public static DatasetField createNewEmptyChildDatasetField(DatasetFieldType dsfType, DatasetFieldCompoundValue compoundValue) {
private static DatasetField createNewEmptyDatasetField(DatasetFieldType dsfType)

and:

public DatasetField copy(DatasetVersion version) {
public DatasetField copyChild(DatasetFieldCompoundValue parent) {
private DatasetField copy(DatasetVersion version, DatasetFieldCompoundValue parent) {


and here is a reference to the entire file:
https://github.com/IQSS/dataverse/blob/master/src/main/java/edu/harvard/iq/dataverse/DatasetField.java

Let me know what else I can provide / do to help.


Top
 Profile  
 
 Post subject: Re: Exception creating new custom constraint
PostPosted: Tue May 13, 2014 7:18 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Gustavo,

Looking at your stacktrace again, I realize that you're apparently not using the latest HV release (this overriding check has been updated and moved to another class), so it may actually be that this issue has already been fixed since then.

Is there any chance you test this with the latest HV version (5.1.1.Final)? I'm not sure though what's the recommended way of updating HV in Glassfish these days; You may try and follow this post on SO: https://stackoverflow.com/questions/10548931/how-to-upgrade-the-hibernate-validator-4-3-0-final-to-the-glassfish-3-1-2). But this is not entirely up to date since it applies to an older version of HV, so some changes may be required. Alternatively you can try to deploy your application on the latest WildFly release.

--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.  [ 6 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.