Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiamondOperatorForVariableDefinitionCheck throws NullPointerException #348

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

Comments

@stephanenicolas
Copy link

@stephanenicolas stephanenicolas commented Jun 4, 2015

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
Copy link
Author

@stephanenicolas stephanenicolas commented Jun 4, 2015

Btw, we have a lot of constructs using

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

@romani
Copy link
Member

@romani 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
Copy link
Member

@romani 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
Copy link
Member

@romani romani commented Jun 7, 2015

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

and

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

@stephanenicolas stephanenicolas commented Jun 7, 2015

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 added a commit that referenced this issue Jun 7, 2015
@romani
Copy link
Member

@romani 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants