[ 
https://issues.apache.org/jira/browse/MDEP-875?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17735616#comment-17735616
 ] 

ASF GitHub Bot commented on MDEP-875:
-------------------------------------

rosti-il commented on code in PR #328:
URL: 
https://github.com/apache/maven-dependency-plugin/pull/328#discussion_r1236665469


##########
src/main/java/org/apache/maven/plugins/dependency/ListRepositoriesMojo.java:
##########
@@ -104,8 +104,10 @@ public boolean visitLeave(DependencyNode node) {
                     .collect(Collectors.groupingBy(
                             repo -> repo.getMirroredRepositories().isEmpty()));
 
-            prepareRemoteRepositoriesList(message, 
repoGroupByMirrors.get(Boolean.TRUE));
-            prepareRemoteMirrorRepositoriesList(message, 
repoGroupByMirrors.get(Boolean.FALSE));
+            prepareRemoteRepositoriesList(
+                    message, repoGroupByMirrors.getOrDefault(Boolean.TRUE, 
Collections.emptyList()));
+            prepareRemoteMirrorRepositoriesList(
+                    message, repoGroupByMirrors.getOrDefault(Boolean.FALSE, 
Collections.emptyList()));

Review Comment:
   In case of an empty list is passed to the 
`prepareRemoteMirrorRepositoriesList()` it doesn't add anything into the 
`message`, so no check is necessary there. The 
`prepareRemoteRepositoriesList()` that is called before 
`prepareRemoteMirrorRepositoriesList()` always appends this title message:
   ```java
           message.append("Project remote repositories used by this 
build:").append(System.lineSeparator());
   ```
   Not appending this title message in `prepareRemoteRepositoriesList()` when 
`prepareRemoteMirrorRepositoriesList()` prints something will look bad, IMHO.
   
   I think a better solution would be checking `repositories.isEmpty()` before 
line 101 and if it is empty just print some other title message and exit from 
`doExecute()`. Would you like me to change this pull request this way? What 
title message for the case of empty `repositories` would you like to be 
printed? For example: "No remote repository is used by this build."





> Regression: list-repositories may produce NPE
> ---------------------------------------------
>
>                 Key: MDEP-875
>                 URL: https://issues.apache.org/jira/browse/MDEP-875
>             Project: Maven Dependency Plugin
>          Issue Type: Bug
>          Components: list-repositories
>    Affects Versions: 3.6.0
>            Reporter: Rostislav Krasny
>            Assignee: Slawomir Jaranowski
>            Priority: Major
>
> Running the *{{mvn 
> org.apache.maven.plugins:maven-dependency-plugin:3.6.0:list-repositories}}* 
> command on a projects that has no repository with mirror or only repositories 
> with mirrors fails with an NPE like in the following example:
> [ERROR] Failed to execute goal 
> org.apache.maven.plugins:maven-dependency-plugin:3.6.0:list-repositories 
> (default-cli) on project d
> emo: Execution default-cli of goal 
> org.apache.maven.plugins:maven-dependency-plugin:3.6.0:list-repositories 
> failed: Cannot invoke
> "java.util.Collection.forEach(java.util.function.Consumer)" because 
> "remoteProjectRepositories" is null -> [Help 1]
> The "project demo" is a simple default project made by 
> https://start.spring.io/
> This regression was introduced by fix of MDEP-853 and exists only in the 
> {{3.6.0}} version of the plugin.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to