Skip to content

Fix crash on SwitchExpr entries if tokens are not stored#4461

Merged
jlerbsc merged 2 commits intojavaparser:masterfrom
johannescoetzee:johannes/fix-no-token-crash
Jun 6, 2024
Merged

Fix crash on SwitchExpr entries if tokens are not stored#4461
jlerbsc merged 2 commits intojavaparser:masterfrom
johannescoetzee:johannes/fix-no-token-crash

Conversation

@johannescoetzee
Copy link
Copy Markdown
Collaborator

@johannescoetzee johannescoetzee commented Jun 6, 2024

When creating SwitchExpr entries with an expression on the RHS, an ExpressionStmt is instantiated with the token range of the child Expression used as the token range for the ExpressionStmt. The problem is that this was not done safely, since expr.getTokenRange() can be empty if the storeTokens configuration option is disabled and in this case the parser would crash. This PR provides a safe alternative for this case, preventing the crash.

This is an old bug that was most likely introduced with the original SwitchExpr support, but I missed it during my refactorings of the code.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.999%. Comparing base (efd064d) to head (5e7a686).
Report is 1 commits behind head on master.

Current head 5e7a686 differs from pull request most recent head 15a21da

Please upload reports for the commit 15a21da to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##            master     #4461       +/-   ##
=============================================
- Coverage   52.003%   51.999%   -0.004%     
=============================================
  Files          507       507               
  Lines        28654     28654               
  Branches      4969      4969               
=============================================
- Hits         14901     14900        -1     
- Misses       11684     11685        +1     
  Partials      2069      2069               
Flag Coverage Δ
AlsoSlowTests 51.999% <ø> (-0.004%) ⬇️
javaparser-core 51.999% <ø> (-0.004%) ⬇️
javaparser-symbol-solver 51.999% <ø> (-0.004%) ⬇️
jdk-10 51.996% <ø> (-0.004%) ⬇️
jdk-11 51.996% <ø> (-0.004%) ⬇️
jdk-12 51.996% <ø> (-0.004%) ⬇️
jdk-13 51.996% <ø> (-0.004%) ⬇️
jdk-14 51.996% <ø> (-0.004%) ⬇️
jdk-15 51.996% <ø> (-0.004%) ⬇️
jdk-16 51.996% <ø> (-0.004%) ⬇️
jdk-17 51.996% <ø> (-0.004%) ⬇️
jdk-18 51.996% <ø> (-0.004%) ⬇️
jdk-8 51.994% <ø> (-0.004%) ⬇️
jdk-9 51.996% <ø> (-0.004%) ⬇️
macos-latest 51.992% <ø> (ø)
ubuntu-latest 51.992% <ø> (-0.004%) ⬇️
windows-latest 51.978% <ø> (-0.004%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5902b93...15a21da. Read the comment docs.

@jlerbsc jlerbsc merged commit 4e02850 into javaparser:master Jun 6, 2024
@jlerbsc jlerbsc added this to the next release milestone Jun 6, 2024
@jlerbsc jlerbsc added the PR: Fixed A PR that offers a fix or correction label Jun 6, 2024
@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Jun 6, 2024

Thank you for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Fixed A PR that offers a fix or correction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants