[
https://issues.apache.org/jira/browse/GROOVY-12136?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18094150#comment-18094150
]
ASF GitHub Bot commented on GROOVY-12136:
-----------------------------------------
Copilot commented on code in PR #2672:
URL: https://github.com/apache/groovy/pull/2672#discussion_r3533058955
##########
subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/generation/BaseGenerator.java:
##########
@@ -187,6 +187,14 @@ protected BlockStatement
wrapAssertionBooleanExpression(ClassNode type, MethodNo
*/
protected BooleanExpression
addCallsToSuperMethodNodeAnnotationClosure(final ClassNode type, final
MethodNode methodNode, final Class<? extends Annotation> annotationType,
BooleanExpression booleanExpression, boolean isPostcondition) {
List<AnnotationNode> contractElementAnnotations =
AnnotationUtils.getAnnotationNodeInHierarchyWithMetaAnnotation(type.getSuperClass(),
methodNode, ClassHelper.makeWithoutCaching(annotationType));
+ if (!isPostcondition) {
+ // An unwoven precondition (@Requires(woven = false)) never
contributes to generated
+ // assertions — inherited arms included, so an override does not
weave a check its
+ // declaring class deliberately left to existing enforcement.
+ contractElementAnnotations = contractElementAnnotations.stream()
+ .filter(a -> !isUnwoven(a))
+ .collect(java.util.stream.Collectors.toList());
+ }
if (contractElementAnnotations.isEmpty()) {
methodNode.putNodeMetaData(META_DATA_USE_INLINE_MODE,
Boolean.TRUE);
} else {
Review Comment:
`META_DATA_USE_INLINE_MODE` is only ever set to `true` and never cleared
when inherited contract annotations are present. Since preconditions are
injected before postconditions (DomainModelInjectionVisitor), enabling inline
mode while processing preconditions can incorrectly cause postcondition weaving
to take the inline path even when inherited postconditions exist, which would
skip inherited postcondition checks. With the new unwoven-precondition
filtering, more methods will hit the “empty inherited preconditions” path and
set this flag, increasing the risk of this cross-contamination.
> groovy-contracts: allow @Requires to opt out of weaving the contract
> --------------------------------------------------------------------
>
> Key: GROOVY-12136
> URL: https://issues.apache.org/jira/browse/GROOVY-12136
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> Just allows the @Requires to act like documentation. Can be used if existing
> libraries already do the validation and you want to make that clearer than
> javadoc alone.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)