-
Notifications
You must be signed in to change notification settings - Fork 332
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
Analyse escaping for local vars #4658
base: main
Are you sure you want to change the base?
Conversation
…ir defining scope
…defining scope or which variables will escape its defining scope
1c83352
to
a38d727
Compare
rewrite-java/src/test/java/org/openrewrite/java/search/FindEscapingVariablesTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/search/FindVariableEscapeLocationsTest.java
Outdated
Show resolved
Hide resolved
Not specifically related to this PR, but thought that I'd share a bit simpler data flow API example given I too found rewrite-security-frameworks a bit difficult to follow originally. I ended up using the data flow API over in rewrite-feature-flags to great effect. |
Thanks @shanman190 for the reference, I'll definitely have a look. I think the Dataflow API needs some introduction material. After I had a breakthrough I'll share some ;) |
…iableEscapeLocationsTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateTest.java
- lines 44-44
rewrite-java/src/test/java/org/openrewrite/java/search/FindEscapingVariablesTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateTest.java
- lines 44-44
What's changed?
I added two visitors that help decide if variables escape and where.
What's your motivation?
When migrating existing code, the question "Is this instance ever leaking its defining scope?" raises from time to time.
Take the migration from
StringBuffer
toStringBuilder
.StringBuilder
is generally in favor, if no synchronization is needed (see JavaDoc StringBuilder).Synchronization is not needed if the instance never escapes its defining scope.
These helping visitors enable such migration by answering the question of escaping vars.
Anything in particular you'd like reviewers to focus on?
Additional ways to leak an instance.
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
I considered the Dataflow API, but I am not fluent enough to archive the same..
Any additional context
This visitor and its helper methods will help @mkarg to realize his migrations for the OpenJDK project.
Checklist