DiamondOperatorForVariableDefinitionCheck throws NullPointerException #348

Closed
stephanenicolas opened this Issue Jun 4, 2015 · 6 comments

Projects

None yet

2 participants

@stephanenicolas

When running 'com.github.sevntu.checkstyle:sevntu-checks:1.13.0', we get a stack trace :

java.lang.NullPointerException
    at com.github.sevntu.checkstyle.checks.coding.DiamondOperatorForVariableDefinitionCheck.isSameTypeArgsInVariableDef(DiamondOperatorForVariableDefinitionCheck.java:86)
    at com.github.sevntu.checkstyle.checks.coding.DiamondOperatorForVariableDefinitionCheck.visitToken(DiamondOperatorForVariableDefinitionCheck.java:65)
    at com.puppycrawl.tools.checkstyle.TreeWalker.notifyVisit(TreeWalker.java:393)
    at com.puppycrawl.tools.checkstyle.TreeWalker.processIter(TreeWalker.java:482)
    at com.puppycrawl.tools.checkstyle.TreeWalker.walk(TreeWalker.java:322)

The problem comes from :

    private static boolean isSameTypeArgsInVariableDef(DetailAST variableDefNode,
            DetailAST typeArgs) {

        DetailAST typeNode = variableDefNode.findFirstToken(TokenTypes.TYPE);
        DetailAST variableDefTypeArgs = typeNode.findFirstToken(TokenTypes.TYPE_ARGUMENTS);

        return variableDefTypeArgs.equalsTree(typeArgs);        // <---     variableDefTypeArgs is null
    }
@stephanenicolas

Btw, we have a lot of constructs using

Type<A> t = new Type<A> {}, that might be where it fails.

@romani
Member
romani commented Jun 4, 2015

@stephanenicolas , thanks a lot.

If you can send share with us exact file - it will be great help, we will recheck code chunk that you have provided.

@romani
Member
romani commented Jun 7, 2015

@stephanenicolas , we already have that case in our UTs - https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputDiamondOperatorForVariableDefinitionCheck.java#L62 , works fine.

please provide exact file to reproduce a problem, you can obfuscate code if you afraid to share source.

@romani
Member
romani commented Jun 7, 2015

reproduced on code:
Class<?>[] resolvedInterfaces = new Class<?>[5];

and

RuleViolation ruleViolation = new ParametricRuleViolation<Object>();
@stephanenicolas

Thx guys, I couldn't have shared the code.
Le 2015-06-06 23:32, "Roman Ivanov" notifications@github.com a écrit :

reproduced on code:
Class[] resolvedInterfaces = new Class[5];


Reply to this email directly or view it on GitHub
#348 (comment)
.

@romani
Member
romani commented Jun 7, 2015

fixed, released as 1.13.2

@romani romani closed this Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment