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

Return inside a code block causes the plugin to crash #153

Open
sbmahs opened this issue Jun 10, 2024 · 0 comments
Open

Return inside a code block causes the plugin to crash #153

sbmahs opened this issue Jun 10, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@sbmahs
Copy link

sbmahs commented Jun 10, 2024

Describe the bug
A conditional return inside a code block (to exit out of the block) causes the plugin to crash and abort the scan.
I expect it is trying to match the return in the code block to the return of the method, which declares a return type.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Gosu class with a method that declares a return type.

  2. Inside that method, execute a code block that tests some condition and does a return to skip to the next item in the .each() list.

  3. In the method, return nothing
    `public function isValid(pAccident : Accident, pOnlyErrors : boolean, pReportingPeriod : ReportingPeriod) : ArrayList {
    var rir = new ArrayList()
    var itemsIgnoredInBatchList = getItemIgnoredInBatchList(pReportingPeriod.StartDate)

    register.eachKeyAndValue( \ code, item -> {
    if (itemsIgnoredInBatchList.contains(code))
    return
    ... more code here ...
    })
    return rir
    `

  4. See the error:
    Cannot invoke "de.friday.sonarqube.gosu.antlr.GosuParser$ExpressionContext.getText()" because "returnedValueContext" is null

Expected behavior
The scanner should see the return as an exit out of the .each() loop, not a return out of the function.
It would also be nice if the plugin reported the file it was working on when it aborts for whatever reason. :-)

Software Versions

Additional context

  1. Scan is called from a Gradle v7.3.3 build
  2. Using OpenJDK 17.0.2
  3. SonarQube server is 10.5 which requires the above versions of Gradle and Java
@sbmahs sbmahs added the bug Something isn't working label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants