Skip to content

Commit

Permalink
HV-2057 Address a few more Sonar-reported issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Oct 18, 2024
1 parent 6be7589 commit 494863c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
public class Group {
public static final Group DEFAULT_GROUP = new Group( Default.class );
private static final String DEFAULT_GROUP_NAME = Default.class.getName();

/**
* The actual group.
Expand Down Expand Up @@ -45,7 +46,12 @@ public boolean equals(Object o) {
}

public boolean isDefaultGroup() {
return getDefiningClass().getName().equals( Default.class.getName() );
return isDefaultGroup( group );
}


public static boolean isDefaultGroup(Class<?> group) {
return DEFAULT_GROUP_NAME.equals( group.getName() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import java.lang.reflect.TypeVariable;

import jakarta.validation.groups.Default;

import org.hibernate.validator.internal.engine.groups.Group;
import org.hibernate.validator.internal.engine.path.PathImpl;
import org.hibernate.validator.internal.engine.valueextraction.AnnotatedObject;
import org.hibernate.validator.internal.engine.valueextraction.ArrayElement;
Expand Down Expand Up @@ -148,7 +147,7 @@ public final void setCurrentValidatedValue(V currentValue) {
}

public final boolean validatingDefault() {
return getCurrentGroup() != null && getCurrentGroup().getName().equals( Default.class.getName() );
return getCurrentGroup() != null && Group.isDefaultGroup( getCurrentGroup() );
}

public final ConstraintLocationKind getConstraintLocationKind() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import jakarta.validation.metadata.ConstructorDescriptor;
import jakarta.validation.metadata.PropertyDescriptor;

import org.hibernate.validator.internal.engine.groups.Group;
import org.hibernate.validator.internal.engine.groups.Sequence;
import org.hibernate.validator.internal.engine.groups.ValidationOrder;
import org.hibernate.validator.internal.engine.groups.ValidationOrderGenerator;
Expand Down Expand Up @@ -577,7 +578,7 @@ private static List<Class<?>> getValidDefaultGroupSequence(Class<?> beanClass, L
validDefaultGroupSequence.add( Default.class );
groupSequenceContainsDefault = true;
}
else if ( group.getName().equals( Default.class.getName() ) ) {
else if ( Group.isDefaultGroup( group ) ) {
throw LOG.getNoDefaultGroupInGroupSequenceException();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public static Type extractConstraintType(Class<? extends ConstraintValidator<?,
}

public static Type extractConstraintValidatorTypeArgumentType(Class<? extends ConstraintValidator<?, ?>> validator, int typeArgumentIndex) {
Contracts.assertNotNull( validator, "validator cannot be null" );
Map<Type, Type> resolvedTypes = new HashMap<>();
Type constraintValidatorType = resolveTypes( resolvedTypes, validator );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public Class<? extends Annotation> annotationType() {
fail();
}
catch (ValidationException e) {
assertThat( e.getMessage() ).startsWith( "HV000082" ).as( "Wrong exception message" );
assertThat( e.getMessage() ).as( "Wrong exception message" ).startsWith( "HV000082" );
}

try {
GetAnnotationAttribute.action( testAnnotation, "foo", Integer.class );
fail();
}
catch (ValidationException e) {
assertThat( e.getMessage() ).startsWith( "HV000083" ).as( "Wrong exception message" );
assertThat( e.getMessage() ).as( "Wrong exception message" ).startsWith( "HV000083" );
}
}
}

0 comments on commit 494863c

Please sign in to comment.