DiamondOperatorForVariableDefinitionCheck throws NullPointerException #348

stephanenicolas opened this Issue Jun 4, 2015 · 6 comments


None yet

2 participants


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

    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

Btw, we have a lot of constructs using

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

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 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 commented Jun 7, 2015

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


RuleViolation ruleViolation = new ParametricRuleViolation<Object>();

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 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