Skip to content

Commit

Permalink
HV-1330 Fix the merge algorithm when dealing with non cascading
Browse files Browse the repository at this point in the history
CascadingTypeParameter
  • Loading branch information
gsmet committed May 11, 2017
1 parent fa23c42 commit 0cc0329
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
Expand Up @@ -112,7 +112,7 @@ public ConstrainedElement build(ConstraintHelper constraintHelper, TypeResolutio
crossParameterContext != null ? crossParameterContext.getConstraints( constraintHelper, typeResolutionHelper, valueExtractorManager ) : Collections.<MetaConstraint<?>>emptySet(),
returnValueContext != null ? returnValueContext.getConstraints( constraintHelper, typeResolutionHelper, valueExtractorManager ) : Collections.<MetaConstraint<?>>emptySet(),
returnValueContext != null ? returnValueContext.getTypeArgumentConstraints( constraintHelper, typeResolutionHelper, valueExtractorManager ) : Collections.<MetaConstraint<?>>emptySet(),
returnValueContext != null ? returnValueContext.getCascadingMetaData() : CascadingTypeParameter.nonCascading( ReflectionHelper.typeOf( executable ) )
returnValueContext != null ? returnValueContext.getCascadingMetaData() : CascadingTypeParameter.nonCascading()
);
}

Expand Down
Expand Up @@ -33,6 +33,9 @@ public class CascadingTypeParameter {

private static final Log LOG = LoggerFactory.make();

private static final CascadingTypeParameter NON_CASCADING =
new CascadingTypeParameter( null, null, false, Collections.emptyMap(), Collections.emptyMap() );

/**
* The enclosing type that defines this type parameter.
*/
Expand Down Expand Up @@ -90,9 +93,8 @@ public CascadingTypeParameter(Type enclosingType, TypeVariable<?> typeParameter,
hasGroupConversionsOnElementOrContainerElements = tmpHasGroupConversionsOnElementOrContainerElements;
}

public static CascadingTypeParameter nonCascading(Type cascadableType) {
// as it's non cascading anyway, we can also treat the arrays as annotated object
return annotatedObject( cascadableType, false, Collections.emptyMap(), Collections.emptyMap() );
public static CascadingTypeParameter nonCascading() {
return NON_CASCADING;
}

public static CascadingTypeParameter annotatedObject(Type cascadableType, boolean cascading,
Expand Down Expand Up @@ -135,6 +137,13 @@ public Map<TypeVariable<?>, CascadingTypeParameter> getContainerElementTypesCasc
}

public CascadingTypeParameter merge(CascadingTypeParameter otherCascadingTypeParameter) {
if ( this == NON_CASCADING ) {
return otherCascadingTypeParameter;
}
if ( otherCascadingTypeParameter == NON_CASCADING ) {
return this;
}

boolean cascading = this.cascading || otherCascadingTypeParameter.cascading;

Map<Class<?>, Class<?>> groupConversions = mergeGroupConversion( this.groupConversions, otherCascadingTypeParameter.groupConversions );
Expand Down
Expand Up @@ -327,7 +327,7 @@ private ConstrainedExecutable findExecutableMetaData(Executable executable) {
if ( annotationProcessingOptions.areReturnValueConstraintsIgnoredFor( executable ) ) {
returnValueConstraints = Collections.emptySet();
typeArgumentsConstraints = Collections.emptySet();
cascadingMetaData = CascadingTypeParameter.nonCascading( ReflectionHelper.typeOf( executable ) );
cascadingMetaData = CascadingTypeParameter.nonCascading();
}
else {
typeArgumentsConstraints = findTypeAnnotationConstraints( executable );
Expand Down Expand Up @@ -401,7 +401,7 @@ private List<ConstrainedParameter> getParameterMetaData(Executable executable) {
i,
parameterConstraints,
Collections.emptySet(),
CascadingTypeParameter.nonCascading( type )
CascadingTypeParameter.nonCascading()
)
);
i++;
Expand Down Expand Up @@ -607,7 +607,7 @@ private CascadingTypeParameter findCascadingMetaData(Executable executable, int
}
catch (ArrayIndexOutOfBoundsException ex) {
log.warn( MESSAGES.constraintOnConstructorOfNonStaticInnerClass(), ex );
return CascadingTypeParameter.nonCascading( ReflectionHelper.typeOf( parameter.getDeclaringExecutable(), i ) );
return CascadingTypeParameter.nonCascading();
}
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ public ConstrainedParameter(ConfigurationSource source,
index,
Collections.<MetaConstraint<?>>emptySet(),
Collections.<MetaConstraint<?>>emptySet(),
CascadingTypeParameter.nonCascading( type )
CascadingTypeParameter.nonCascading()
);
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ public ConstrainedType(ConfigurationSource source, Class<?> beanClass, Set<MetaC
ConstrainedElementKind.TYPE,
constraints,
Collections.emptySet(),
CascadingTypeParameter.nonCascading( beanClass )
CascadingTypeParameter.nonCascading()
);

this.beanClass = beanClass;
Expand Down
Expand Up @@ -16,7 +16,6 @@
import java.lang.reflect.TypeVariable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -210,13 +209,11 @@ private ConstrainedExecutable parseExecutableType(String defaultPackage,
// parse the return value
Set<MetaConstraint<?>> returnValueConstraints = new HashSet<>();
Set<MetaConstraint<?>> returnValueTypeArgumentConstraints = new HashSet<>();
List<CascadingTypeParameter> cascadingTypeParameters = new ArrayList<>();
CascadingTypeParameter cascadingMetaData = parseReturnValueType(
returnValueType,
executable,
returnValueConstraints,
returnValueTypeArgumentConstraints,
cascadingTypeParameters,
defaultPackage
);

Expand Down Expand Up @@ -268,10 +265,9 @@ private CascadingTypeParameter parseReturnValueType(ReturnValueType returnValueT
Executable executable,
Set<MetaConstraint<?>> returnValueConstraints,
Set<MetaConstraint<?>> returnValueTypeArgumentConstraints,
List<CascadingTypeParameter> cascadingTypeParameters,
String defaultPackage) {
if ( returnValueType == null ) {
return CascadingTypeParameter.nonCascading( ReflectionHelper.typeOf( executable ) );
return CascadingTypeParameter.nonCascading();
}

ConstraintLocation constraintLocation = ConstraintLocation.forReturnValue( executable );
Expand Down
Expand Up @@ -265,9 +265,7 @@ public void cascadingIterableParameter() {
}
}

// FIXME HV-1330: we have transient failures with this test
// sometimes the exception is not thrown
@Test(enabled = false)
@Test
public void cascadingArrayParameter() {
Customer customer = new Customer( null );

Expand Down

0 comments on commit 0cc0329

Please sign in to comment.