cflint / CFLint

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

NPE parsing `if` condition with `not` #646

Closed sbleon closed 4 years ago

sbleon commented 4 years ago

File:

component {
  public struct function foo() {
    if (not (['quantity'].contains('total'))) {
      abort;
    }
  }
}

Result:

java.lang.NullPointerException
    at cfml.parsing.cfscript.script.CFIfStatement.Decompile(CFIfStatement.java:35)
    at cfml.parsing.cfscript.script.CFCompoundStatement.Decompile(CFCompoundStatement.java:60)
    at cfml.parsing.cfscript.script.CFCompoundStatement.Decompile(CFCompoundStatement.java:60)
    at cfml.parsing.cfscript.script.CFCompDeclStatement.Decompile(CFCompDeclStatement.java:79)
    at com.cflint.plugins.core.ComponentLengthChecker.expression(ComponentLengthChecker.java:20)
    at com.cflint.CFLint.scanExpression(CFLint.java:1021)
    at com.cflint.CFLint.process(CFLint.java:816)
    at com.cflint.CFLint.process(CFLint.java:340)
    at com.cflint.CFLint.scan(CFLint.java:295)
    at com.cflint.CFLint.scan(CFLint.java:206)
    at com.cflint.api.CFLintAPI.scan(CFLintAPI.java:65)
    at com.cflint.cli.CFLintCLI.execute(CFLintCLI.java:371)
    at com.cflint.cli.CFLintCLI.main(CFLintCLI.java:339)
Error: "null" Location: cfml.parsing.cfscript.script.CFIfStatement.Decompile(CFIfStatement.java:35)
com.cflint.exception.CFLintScanException: java.lang.NullPointerException
    at com.cflint.CFLint.process(CFLint.java:347)
    at com.cflint.CFLint.scan(CFLint.java:295)
    at com.cflint.CFLint.scan(CFLint.java:206)
    at com.cflint.api.CFLintAPI.scan(CFLintAPI.java:65)
    at com.cflint.cli.CFLintCLI.execute(CFLintCLI.java:371)
    at com.cflint.cli.CFLintCLI.main(CFLintCLI.java:339)
Caused by: java.lang.NullPointerException
    at cfml.parsing.cfscript.script.CFIfStatement.Decompile(CFIfStatement.java:35)
    at cfml.parsing.cfscript.script.CFCompoundStatement.Decompile(CFCompoundStatement.java:60)
    at cfml.parsing.cfscript.script.CFCompoundStatement.Decompile(CFCompoundStatement.java:60)
    at cfml.parsing.cfscript.script.CFCompDeclStatement.Decompile(CFCompDeclStatement.java:79)
    at com.cflint.CFLint.reportRule(CFLint.java:1375)
    at com.cflint.CFLint.reportRule(CFLint.java:1232)
    at com.cflint.CFLint.scanExpression(CFLint.java:1028)
    at com.cflint.CFLint.process(CFLint.java:816)
    at com.cflint.CFLint.process(CFLint.java:340)
    ... 5 more
Error: "java.lang.NullPointerException" Location: com.cflint.CFLint.process(CFLint.java:347)
Issue
Severity:ERROR
Message code:PARSE_ERROR
    File:/Users/leon/code/csubs/internal/objects/analytics.cfc
    Column:24
    Line:3
        Message:Unable to parse
        Variable:']' in function: 
        Expression:null
Issue
Severity:ERROR
Message code:MISSING_SEMI
    File:/Users/leon/code/csubs/internal/objects/analytics.cfc
    Column:-2
    Line:3
        Message:End of statement(;) expected after 
        Variable:'null' in function: 
        Expression:null

Total files:1
Total lines:8

Issue counts:2
PARSE_ERROR:1
MISSING_SEMI:1

Total issues:2
Total errors:2

Workaround: Changing not to ! eliminates the NPE, but the PARSE_ERROR remains.

sbleon commented 4 years ago

CFLint v1.4.1

sbleon commented 4 years ago

This problem still exists in the current dev branch.

sbleon commented 4 years ago

This appears to be fixed in (as of yet unreleased) version 1.5.0. Thanks!