Skip to content

HV-1591 Log warning when @Valid is used improperly #1635

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,12 @@ private Map<TypeVariable<?>, CascadingMetaDataBuilder> getTypeParametersCascadin
Map<TypeVariable<?>, CascadingMetaDataBuilder> nestedTypeParametersCascadingMetadata = getTypeParametersCascadingMetaDataForAnnotatedType(
annotatedTypeArgument );

boolean annotatedWithValid = annotatedTypeArgument.isAnnotationPresent( Valid.class );
if ( annotatedWithValid && annotatedParameterizedType.isAnnotationPresent( Valid.class ) ) {
LOG.validAppliedTwice( annotatedParameterizedType );
}
typeParametersCascadingMetadata.put( typeParameters[i], new CascadingMetaDataBuilder( annotatedParameterizedType.getType(), typeParameters[i],
annotatedTypeArgument.isAnnotationPresent( Valid.class ), nestedTypeParametersCascadingMetadata,
getGroupConversions( annotatedTypeArgument ) ) );
annotatedWithValid, nestedTypeParametersCascadingMetadata, getGroupConversions( annotatedTypeArgument ) ) );
i++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.AnnotatedParameterizedType;
import java.lang.reflect.Executable;
import java.lang.reflect.Member;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -946,4 +947,8 @@ ConstraintDefinitionException getConstraintValidatorDefinitionConstraintMismatch
@LogMessage(level = DEBUG)
@Message(id = 269, value = "Unable to enable secure XML feature processing when loading %1$s: %2$s")
void unableToEnableSecureFeatureProcessingSchemaXml(String fileName, String message);

@LogMessage(level = WARN)
@Message(id = 270, value = "For a given container, the `@Valid` annotation should either be put on the container itself or on the type argument(s) of the container, but not both: %s")
void validAppliedTwice(AnnotatedParameterizedType annotatedParameterizedType);
}
5 changes: 3 additions & 2 deletions engine/src/test/resources/log4j2.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# License: Apache License, Version 2.0
# See the LICENSE file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.

status = error
rootLogger.level = error
rootLogger.appenderRefs = console
rootLogger.appenderRef.console.ref = console

# Direct log messages to stdout
appender.console.type = Console
Expand Down