-
Notifications
You must be signed in to change notification settings - Fork 354
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
Does that imply that this PR will change or that it will get revoked? I am actively waiting for this visitors to be finally usable. Thanks for updating. |
Hi @mkarg ATM I have not the resources to dig deep into the FlowAPI to implement the alternative solution. I would suggest to postpone this reimplementation but stick with the API fur a further versions. Would that work for you? |
I personally have no strong feelings how the visitors are implemented as long as there is a stable API to call them. |
package com.sample; | ||
public class Foo{ | ||
void test() { | ||
StringBuilder /*~~>*/sb = new StringBuilder(); |
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.
As other
is itself non-escaping, sb
essentially is non-escpaing, too.
package com.sample; | ||
public class Foo{ | ||
void test() { | ||
StringBuilder /*~~>*/sb = new StringBuilder(); |
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.
As other
is itself non-escaping, sb
essentially is non-escpaing, too.
…penrewrite#4659) * Keep multiple whitelines and same comments from the gitignore file * Keep multiple whitelines and same comments from the gitignore file
…penrewrite#4657) * working draft * IntelliJ formatting * Update rewrite-yaml/src/main/java/org/openrewrite/yaml/search/FindProperty.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Sam Snyder <sam@moderne.io> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* Update for rewrite 8.0 * Cosmetics * Fix a few more issues * Fix a few more test failures * Fix a few more test failures * Upgrade recipes to new `JavaTemplate` API * Replace `getRecipeList()` overrides with `@Getter(lazy = true)` property * Consistently use `latest.release` or `latest.integration` * Revert "Replace `getRecipeList()` overrides with `@Getter(lazy = true)` property" This reverts commit 897d59e79c9515564da45911ce2246934c5b1ae7. * Migrate to new `Recipe#getInitialState(ExecutionContext)` API * Polish * Fix a broken test Due to reversal of logic after inlining `doAfterVisit()` logic. * Fix another broken test We should change the `UpgradeDependencyVersion` in `rewrite-java-dependencies` so that workarounds like this are not necessary. * Fix last failing test (use `doAfterVisit()` again) --------- Co-authored-by: Sam Snyder <sam@moderne.io>
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.NullableOnMethodReturnType?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne <team@moderne.io>
* Add test * Added compilation unit test * Swap expected and actual * Restore previous behavior --------- Co-authored-by: Laurens Westerlaken <laurens.westerlaken@jdriven.com>
…te#4673) * Polish tests * Polish --------- Co-authored-by: Tim te Beek <tim@moderne.io>
…erpolation is used on a version number
…eter is specified
…penrewrite#4677) * Remove redundant space for DeleteMethodArgument when argumentIndex=0 Signed-off-by: kuchang <kuchang@ebay.com> * Update FindPluginsTest.java * Adopt prefix of removed element --------- Signed-off-by: kuchang <kuchang@ebay.com> Co-authored-by: Tim te Beek <tim@moderne.io>
This is especially important for the YAML implementation, which applies the `ReplaceAliasWithAnchorValueVisitor` visitor to all elements.
Only apply `ReplaceAliasWithAnchorValueVisitor` to `Yaml.Document` elements. See: openrewrite#4650
* Add some initial tests * Add append functionality * Add markers * Fix constructor after merge * Polish code * Verify default behavior retained for declarative recipes through use of `null` in tests * Add test that fails due to unexpected second cycle * Adopt Markers.findFirst * Add newline to indicate Marker is on assignment * Fix test and polish * Update rewrite-java/src/main/java/org/openrewrite/java/AddOrUpdateAnnotationAttribute.java Co-authored-by: Tim te Beek <tim@moderne.io> --------- Co-authored-by: Tim te Beek <tim@moderne.io>
…4688) * Make `FindMissingTypes` stricter for method invocations Validate argument count with respect to parameter count. * Try to fix linking in `ReloadableJava17JavadocVisitor` * Try to fix `TypeUtils#isAssignableTo()` * Also update Java 11 and Java 21 Javadoc visitors * Also update Java 11 and Java 21 Javadoc visitors * More updates and simplifications * Corner case in `TypeUtils`
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.gradle.UpdateGradleWrapper?organizationId=T3BlblJld3JpdGU%3D#defaults=W3sibmFtZSI6ImFkZElmTWlzc2luZyIsInZhbHVlIjoiRmFsc2UifV0= Co-authored-by: Moderne <team@moderne.io>
I didn't even realize the recipe had this feature.
* Add `TypeUtils` tests for primitives * Correct `TypeUtils#isAssignableTo()` for primitive array types * New `TypeUtils#isAssignableTo()` API We need to consider the "position" when performing the assignability check. I.e. check if a parameterized type compared against a generic type variable is used in a context where the generic type parameter is bound by the parameterized type or not. * Implement new API * Remove one more `stream()` call * Update Javadoc visitors to use `TypeUtils#isAssignableTo()` correctly * Correction * Corrections * Corrections * More Javadoc fixes * Add missing `@MinimumJava11` annotation
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