Issue #1903: Fixed NPE in MutableExceptionCheck.isExtendedClassNamedAsException .

This commit is contained in:
Andrei Selkin 2015-09-03 14:17:07 +03:00 committed by Roman Ivanov
parent 0b23dba45a
commit 0689f76ab3
3 changed files with 25 additions and 1 deletions

View File

@ -155,7 +155,7 @@ public final class MutableExceptionCheck extends AbstractFormatCheck {
final DetailAST extendsClause = ast.findFirstToken(TokenTypes.EXTENDS_CLAUSE);
if (extendsClause != null) {
DetailAST currentNode = extendsClause;
while (currentNode.getType() != TokenTypes.IDENT) {
while (currentNode.getLastChild() != null) {
currentNode = currentNode.getLastChild();
}
final String extendedClassName = currentNode.getText();

View File

@ -35,6 +35,18 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class MutableExceptionCheckTest extends BaseCheckTestSupport {
@Test
public void testClassExtendsGenericClass() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(MutableExceptionCheck.class);
String[] expected = {
};
verify(checkConfig, getPath("design" + File.separator
+ "InputMutableExceptionClassExtendsGenericClass.java"), expected);
}
@Test
public void testDefault() throws Exception {
DefaultConfiguration checkConfig = createCheckConfig(MutableExceptionCheck.class);

View File

@ -0,0 +1,12 @@
package com.puppycrawl.tools.checkstyle.design;
import java.util.concurrent.atomic.AtomicReference;
/**
* Convenience class for holding an {@link Exception} in a thread-safe way
*/
public class InputMutableExceptionClassExtendsGenericClass extends AtomicReference<Exception> { // NPE is not expected
private static final long serialVersionUID = 1L;
}