cflint / CFLint

Static code analysis for CFML (a linter)
BSD 3-Clause "New" or "Revised" License
174 stars 84 forks source link

NPE with `if`, inline array, and method call #650

Closed sbleon closed 5 years ago

sbleon commented 5 years ago

Env: pre-1.5.0 code built from dev at rev adc842f712118228258918ed1f21106eb14e5dfc.

File:

component {
  if (!['all'].foo()) {
  }
}

Result:

com.cflint.exception.CFLintScanException: java.lang.NullPointerException
    at com.cflint.CFLint.process(CFLint.java:346)
    at com.cflint.CFLint.scan(CFLint.java:294)
    at com.cflint.CFLint.scan(CFLint.java:204)
    at com.cflint.api.CFLintAPI.scan(CFLintAPI.java:66)
    at com.cflint.cli.CFLintCLI.execute(CFLintCLI.java:376)
    at com.cflint.cli.CFLintCLI.main(CFLintCLI.java:343)
Caused by: java.lang.NullPointerException
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
    at cfml.parsing.cfscript.walker.CFExpressionVisitor.visitBaseExpression(CFExpressionVisitor.java:223)
    at cfml.parsing.cfscript.walker.CFExpressionVisitor.visitBaseExpression(CFExpressionVisitor.java:78)
    at cfml.CFSCRIPTParser$BaseExpressionContext.accept(CFSCRIPTParser.java:5890)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
    at cfml.CFSCRIPTParserBaseVisitor.visitCondition(CFSCRIPTParserBaseVisitor.java:209)
    at cfml.parsing.cfscript.walker.CFExpressionVisitor.visitCondition(CFExpressionVisitor.java:128)
    at cfml.parsing.cfscript.walker.CFExpressionVisitor.visitCondition(CFExpressionVisitor.java:78)
    at cfml.CFSCRIPTParser$ConditionContext.accept(CFSCRIPTParser.java:2639)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitIfStatement(CFScriptStatementVisitor.java:309)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitIfStatement(CFScriptStatementVisitor.java:102)
    at cfml.CFSCRIPTParser$IfStatementContext.accept(CFSCRIPTParser.java:2750)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitStatement(CFScriptStatementVisitor.java:285)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitStatement(CFScriptStatementVisitor.java:102)
    at cfml.CFSCRIPTParser$StatementContext.accept(CFSCRIPTParser.java:2320)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
    at cfml.CFSCRIPTParserBaseVisitor.visitElement(CFSCRIPTParserBaseVisitor.java:48)
    at cfml.CFSCRIPTParser$ElementContext.accept(CFSCRIPTParser.java:564)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
    at cfml.CFSCRIPTParserBaseVisitor.visitComponentGuts(CFSCRIPTParserBaseVisitor.java:167)
    at cfml.CFSCRIPTParser$ComponentGutsContext.accept(CFSCRIPTParser.java:2149)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitComponentDeclaration(CFScriptStatementVisitor.java:117)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitComponentDeclaration(CFScriptStatementVisitor.java:102)
    at cfml.CFSCRIPTParser$ComponentDeclarationContext.accept(CFSCRIPTParser.java:432)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
    at cfml.CFSCRIPTParserBaseVisitor.visitScriptBlock(CFSCRIPTParserBaseVisitor.java:20)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitScriptBlock(CFScriptStatementVisitor.java:110)
    at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitScriptBlock(CFScriptStatementVisitor.java:102)
    at cfml.CFSCRIPTParser$ScriptBlockContext.accept(CFSCRIPTParser.java:258)
    at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
    at cfml.parsing.CFMLParser.parseScript(CFMLParser.java:539)
    at com.cflint.CFLint.process(CFLint.java:337)
    ... 5 more
Error: "java.lang.NullPointerException" Location: com.cflint.CFLint.process(CFLint.java:346)
Issue
Severity:ERROR
Message code:PARSE_ERROR
    File:/Users/leon/code/csubs/internal/objects/configuration.cfc
    Column:12
    Line:2
        Message:Unable to parse
        Variable:']' in function: 
        Expression:null
Issue
Severity:ERROR
Message code:MISSING_SEMI
    File:/Users/leon/code/csubs/internal/objects/configuration.cfc
    Column:7
    Line:2
        Message:End of statement(;) expected after 
        Variable:'null' in function: 
        Expression:null

Total files:1
Total lines:5

Issue counts:2
PARSE_ERROR:1
MISSING_SEMI:1

Total issues:2
Total errors:2
ryaneberly commented 5 years ago

fixed in cfparser 2.11.0