This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch MENFORCER-314
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git

commit d44147fd4b4ab12e973ecdceab62cd6276519154
Author: Falko Modler <fa...@users.noreply.github.com>
AuthorDate: Sat Oct 27 17:07:02 2018 +0200

    [MENFORCER-314] - Warn if EnforcerRuleException has no message
    
    This should help to find out why DependencyConvergence
    sometimes fails without providing a message.
---
 .../apache/maven/plugins/enforcer/EnforceMojo.java    | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git 
a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
 
b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
index 3d623fc..d8ed53a 100644
--- 
a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
+++ 
b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
@@ -218,16 +218,27 @@ public class EnforceMojo
                     }
                     else
                     {
+                        // log a warning in case the exception message is 
missing
+                        // so that the user can figure out what is going on
+                        final String exceptionMessage = e.getMessage();
+                        if ( exceptionMessage != null )
+                        {
+                            log.debug( "Adding " + level + " message due to 
exception", e );
+                        }
+                        else
+                        {
+                            log.warn( "Rule " + i + ": " + currentRule + " 
failed without a message", e );
+                        }
+                        // add the 'failed/warned' message including 
exceptionMessage
+                        // which might be null in rare cases
                         if ( level == EnforcerLevel.ERROR )
                         {
                             hasErrors = true;
-                            list.add( "Rule " + i + ": " + currentRule + " 
failed with message:\n" + e.getMessage() );
-                            log.debug( "Adding failure due to exception", e );
+                            list.add( "Rule " + i + ": " + currentRule + " 
failed with message:\n" + exceptionMessage );
                         }
                         else
                         {
-                            list.add( "Rule " + i + ": " + currentRule + " 
warned with message:\n" + e.getMessage() );
-                            log.debug( "Adding warning due to exception", e );
+                            list.add( "Rule " + i + ": " + currentRule + " 
warned with message:\n" + exceptionMessage );
                         }
                     }
                 }

Reply via email to