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

NPE parsing catch with custom error type but no variable #647

Closed
sbleon opened this issue Oct 11, 2019 · 6 comments
Closed

NPE parsing catch with custom error type but no variable #647

sbleon opened this issue Oct 11, 2019 · 6 comments
Assignees
Milestone

Comments

@sbleon
Copy link

sbleon commented Oct 11, 2019

File:

component {
  try {
  } catch (org.example.whateverError) {
  }
}

Result:

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.walker.CFExpressionVisitor.visitIdentifier(CFExpressionVisitor.java:325)
	at cfml.parsing.cfscript.walker.CFExpressionVisitor.visitIdentifier(CFExpressionVisitor.java:77)
	at cfml.CFSCRIPTParser$IdentifierContext.accept(CFSCRIPTParser.java:8840)
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitTryCatchStatement(CFScriptStatementVisitor.java:351)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitTryCatchStatement(CFScriptStatementVisitor.java:100)
	at cfml.CFSCRIPTParser$TryCatchStatementContext.accept(CFSCRIPTParser.java:3226)
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitStatement(CFScriptStatementVisitor.java:282)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitStatement(CFScriptStatementVisitor.java:100)
	at cfml.CFSCRIPTParser$StatementContext.accept(CFSCRIPTParser.java:2352)
	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:563)
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
	at cfml.CFSCRIPTParserBaseVisitor.visitComponentGuts(CFSCRIPTParserBaseVisitor.java:160)
	at cfml.CFSCRIPTParser$ComponentGutsContext.accept(CFSCRIPTParser.java:2245)
	at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitComponentDeclaration(CFScriptStatementVisitor.java:115)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitComponentDeclaration(CFScriptStatementVisitor.java:100)
	at cfml.CFSCRIPTParser$ComponentDeclarationContext.accept(CFSCRIPTParser.java:431)
	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:108)
	at cfml.parsing.cfscript.walker.CFScriptStatementVisitor.visitScriptBlock(CFScriptStatementVisitor.java:100)
	at cfml.CFSCRIPTParser$ScriptBlockContext.accept(CFSCRIPTParser.java:257)
	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:338)
	... 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/tests/TEST_pdfThumbnailService.cfc
	Column:35
	Line:3
		Message:Unable to parse
		Variable:'whateverError' in function: 
		Expression:null


Total files:1
Total lines:6

Issue counts:1
PARSE_ERROR:1

Total issues:1
Total errors:1

Workaround:
Add a variable name after the custom error type:

component {
  try {
  } catch (org.example.whateverError e) {
  }
}

CFLint v1.4.1

@sbleon
Copy link
Author

sbleon commented Oct 16, 2019

This problem still exists in the current dev branch.

@ryaneberly ryaneberly added this to the 1.5.0 milestone Nov 16, 2019
ryaneberly added a commit to cfparser/cfparser that referenced this issue Nov 18, 2019
@ryaneberly ryaneberly self-assigned this Nov 18, 2019
@ryaneberly
Copy link
Contributor

fixed in cfparser dev.

@KamasamaK
Copy link
Collaborator

Another surprising difference between ACF and Lucee. I'm not sure why Lucee allows this, but it's too late for that now.

@ryaneberly
Copy link
Contributor

LOL. cfparser will assume org.example.whateverError is the variable name. Is org.example.whateverError really the component name in Lucee? I suspect not.

@ryaneberly
Copy link
Contributor

yeah.... lucee preserves the cfcatch name regardless of whether you name the catch var or not. The initial example code is actually a bug IMO. But cfparser shouldn't have blown up.

https://trycf.com/gist/c890235192464fcb91eb8ab66ad27e18/lucee5?theme=monokai

ryaneberly added a commit that referenced this issue Nov 19, 2019
@ryaneberly
Copy link
Contributor

fixed in dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants