Copilot commented on code in PR #6413:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6413#discussion_r2253920178


##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java:
##########
@@ -82,5 +81,8 @@ static <T extends NamedElement> void 
addIfNotPresent(Collection<T> target, T sou
         if (target.stream().noneMatch(namedElement -> 
Objects.equals(namedElement.getName(), source.getName()))) {
             target.add(source);
         }
+        if (target.stream().anyMatch(namedElement -> 
namedElement.getName().isEmpty() && source.getName().isEmpty() && namedElement 
instanceof Import)) {

Review Comment:
   This condition could cause a NullPointerException if 
`namedElement.getName()` or `source.getName()` returns null. Add null checks 
before calling `isEmpty()`.
   ```suggestion
           if (target.stream().anyMatch(namedElement ->
                   namedElement instanceof Import &&
                   namedElement.getName() != null &&
                   source.getName() != null &&
                   namedElement.getName().isEmpty() &&
                   source.getName().isEmpty())) {
   ```



##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/UnnamedImportUtils.java:
##########
@@ -82,5 +81,8 @@ static <T extends NamedElement> void 
addIfNotPresent(Collection<T> target, T sou
         if (target.stream().noneMatch(namedElement -> 
Objects.equals(namedElement.getName(), source.getName()))) {
             target.add(source);
         }
+        if (target.stream().anyMatch(namedElement -> 
namedElement.getName().isEmpty() && source.getName().isEmpty() && namedElement 
instanceof Import)) {
+            target.add(source);
+        }

Review Comment:
   The logic for handling unnamed imports is unclear and potentially redundant. 
This condition will always add the source element when both names are empty and 
the target contains an Import with an empty name, which could lead to duplicate 
entries. Consider clarifying the intended behavior or using a more explicit 
approach.
   ```suggestion
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to