Skip to content

Commit 36630f6

Browse files
Sergey Chernovslachiewicz
authored andcommitted
[MNG-6626] fix DefaultExceptionHandler NPE
Closes #241
1 parent 2760e3e commit 36630f6

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,13 @@ else if ( exception instanceof PluginExecutionException )
209209
{
210210
Throwable cause2 = cause.getCause();
211211

212-
if ( cause2 instanceof NoClassDefFoundError
213-
&& cause2.getMessage().contains( "org/sonatype/aether/" ) )
212+
if ( cause2 instanceof NoClassDefFoundError )
214213
{
215-
reference = "AetherClassNotFound";
214+
String message = cause2.getMessage();
215+
if ( message != null && message.contains( "org/sonatype/aether/" ) )
216+
{
217+
reference = "AetherClassNotFound";
218+
}
216219
}
217220
}
218221

maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@
2222
import java.io.IOException;
2323
import java.net.ConnectException;
2424

25+
import org.apache.maven.model.Plugin;
26+
import org.apache.maven.plugin.MojoExecution;
2527
import org.apache.maven.plugin.MojoExecutionException;
2628

27-
import junit.framework.TestCase;
29+
import org.apache.maven.plugin.PluginContainerException;
30+
import org.apache.maven.plugin.PluginExecutionException;
31+
import org.apache.maven.plugin.descriptor.MojoDescriptor;
32+
import org.apache.maven.plugin.descriptor.PluginDescriptor;
33+
import org.junit.Test;
34+
35+
import static org.junit.Assert.assertEquals;
2836

2937
/**
3038
* @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>
3139
*/
3240
public class DefaultExceptionHandlerTest
33-
extends TestCase
3441
{
3542
/**
3643
* Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
@@ -42,11 +49,11 @@ public class DefaultExceptionHandlerTest
4249
* http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
4350
* </p>
4451
*/
52+
@Test
4553
public void testJdk7ipv6()
4654
{
4755
ConnectException connEx = new ConnectException( "Connection refused: connect" );
48-
IOException ioEx = new IOException( "Unable to establish loopback connection" );
49-
ioEx.initCause( connEx );
56+
IOException ioEx = new IOException( "Unable to establish loopback connection", connEx );
5057
MojoExecutionException mojoEx =
5158
new MojoExecutionException( "Error executing Jetty: Unable to establish loopback connection", ioEx );
5259

@@ -57,4 +64,42 @@ public void testJdk7ipv6()
5764
assertEquals( expectedReference, exceptionSummary.getReference() );
5865

5966
}
67+
68+
@Test
69+
public void testHandleExceptionAetherClassNotFound()
70+
{
71+
Throwable cause2 = new NoClassDefFoundError( "org/sonatype/aether/RepositorySystem" );
72+
Plugin plugin = new Plugin();
73+
Exception cause = new PluginContainerException( plugin, null, null, cause2 );
74+
PluginDescriptor pluginDescriptor = new PluginDescriptor();
75+
MojoDescriptor mojoDescriptor = new MojoDescriptor();
76+
mojoDescriptor.setPluginDescriptor( pluginDescriptor );
77+
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
78+
Throwable exception = new PluginExecutionException( mojoExecution, null, cause );
79+
80+
DefaultExceptionHandler handler = new DefaultExceptionHandler();
81+
ExceptionSummary summary = handler.handleException( exception );
82+
83+
String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound";
84+
assertEquals( expectedReference, summary.getReference() );
85+
}
86+
87+
@Test
88+
public void testHandleExceptionNoClassDefFoundErrorNull()
89+
{
90+
Throwable cause2 = new NoClassDefFoundError();
91+
Plugin plugin = new Plugin();
92+
Exception cause = new PluginContainerException( plugin, null, null, cause2 );
93+
PluginDescriptor pluginDescriptor = new PluginDescriptor();
94+
MojoDescriptor mojoDescriptor = new MojoDescriptor();
95+
mojoDescriptor.setPluginDescriptor( pluginDescriptor );
96+
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
97+
Throwable exception = new PluginExecutionException( mojoExecution, null, cause );
98+
99+
DefaultExceptionHandler handler = new DefaultExceptionHandler();
100+
ExceptionSummary summary = handler.handleException( exception );
101+
102+
String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException";
103+
assertEquals( expectedReference, summary.getReference() );
104+
}
60105
}

0 commit comments

Comments
 (0)