Skip to content

Conversation

johanneskloos
Copy link
Contributor

Fixes #3710.
The idea of the fix is that the scope in inner class object creation expressions, e.g., makeOuter().new Inner(), can cause resolution loops in just the same way that the scope of a field access or method call can, and should be handled in the same way.

Copy link

codecov bot commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.194%. Comparing base (0efeae1) to head (84441d0).
Report is 7 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #4704       +/-   ##
===============================================
- Coverage     58.198%   58.194%   -0.005%     
  Complexity      2497      2497               
===============================================
  Files            670       670               
  Lines          38719     38720        +1     
  Branches        7022      7023        +1     
===============================================
- Hits           22534     22533        -1     
- Misses         13293     13295        +2     
  Partials        2892      2892               
Flag Coverage Δ
AlsoSlowTests 58.194% <100.000%> (-0.005%) ⬇️
javaparser-core 58.194% <100.000%> (-0.005%) ⬇️
javaparser-symbol-solver 58.194% <100.000%> (-0.005%) ⬇️
jdk-10 57.753% <100.000%> (-0.005%) ⬇️
jdk-11 57.753% <100.000%> (-0.005%) ⬇️
jdk-12 57.753% <100.000%> (-0.005%) ⬇️
jdk-13 57.753% <100.000%> (-0.005%) ⬇️
jdk-14 57.993% <100.000%> (-0.005%) ⬇️
jdk-15 57.993% <100.000%> (-0.005%) ⬇️
jdk-16 57.967% <100.000%> (-0.005%) ⬇️
jdk-17 58.122% <100.000%> (-0.005%) ⬇️
jdk-18 58.122% <100.000%> (-0.005%) ⬇️
jdk-8 57.754% <100.000%> (-0.005%) ⬇️
jdk-9 57.750% <100.000%> (-0.005%) ⬇️
macos-latest 58.186% <100.000%> (-0.005%) ⬇️
ubuntu-latest 58.181% <100.000%> (-0.005%) ⬇️
windows-latest 58.176% <100.000%> (-0.005%) ⬇️

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

Files with missing lines Coverage Δ
...arsermodel/contexts/AbstractJavaParserContext.java 73.509% <100.000%> (-1.157%) ⬇️

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 0910acd...84441d0. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johanneskloos johanneskloos force-pushed the johanneskloos/3710-infinite-recursion-involving-object-creation-scopes branch from 7bc20b7 to dece4d5 Compare April 2, 2025 16:14
// is not the same as the current node.
while (notMethodNode instanceof MethodCallExpr
|| notMethodNode instanceof FieldAccessExpr
|| (notMethodNode instanceof ObjectCreationExpr && notMethodNode.hasScope())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that the expression new A().new B() can be solved correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining simply and clearly why this has been added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a comment, and a unit test for the case you mentioned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I added two unit tests :)

"com.github.javaparser.symbolsolver.Outer.make()", resolvedMethod.getQualifiedSignature());
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include these classes in the source code to be parsed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

This is adapted from my own example and the example in 3710, to make up
a more-or-less minimal reproduction case.
Without this check, the symbol resolver would loop
between resolving a method call (used as scope argument
for a new object creation) and resolving the method call's
scope.
@johanneskloos johanneskloos force-pushed the johanneskloos/3710-infinite-recursion-involving-object-creation-scopes branch from 353f1ad to c189a15 Compare April 3, 2025 10:47
@johanneskloos johanneskloos requested a review from jlerbsc April 3, 2025 10:48
@johanneskloos johanneskloos force-pushed the johanneskloos/3710-infinite-recursion-involving-object-creation-scopes branch from c189a15 to 84441d0 Compare April 3, 2025 10:54
@jlerbsc jlerbsc merged commit ae30bb4 into javaparser:master Apr 3, 2025
35 checks passed
@jlerbsc
Copy link
Collaborator

jlerbsc commented Apr 3, 2025

Thank you for your contribution

@jlerbsc jlerbsc added this to the next release milestone Apr 3, 2025
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

Successfully merging this pull request may close these issues.

Inner class instantiation statement cause StackOverflowError when trying to resolve method call to the declaration

2 participants