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

Add support for variables in RemoveWas2LibertyNonPortableJndiLookup recipe #23

Merged
merged 3 commits into from
Nov 7, 2024

Conversation

rlsanders4
Copy link
Contributor

@rlsanders4 rlsanders4 commented Nov 7, 2024

What's changed?

The RemoveWas2LibertyNonPortableJndiLookup recipe is intended to remove Hashtable.put() method invocations using the following WebSphere properties:

java.naming.factory.initial
java.naming.provider.url

Currently, this only works if these properties are specified in the method invocation as string literals. With this PR adds support for the case in which these parameters are passed into the method invocation as variables.

What's your motivation?

The RemoveWas2LibertyNonPortableJndiLookup recipe will only remove method invocations using properties that are specified as string literals, but it would fail to remove method invocation using properties specifed using variables.

For example, this method invocation will be removed:

Hashtable ht = new Hashtable();
ht.put("java.naming.factory.initial", "");

But this method invocation will not to be removed:

String initial = "java.naming.factory.initial"

Hashtable ht = new Hashtable();
ht.put(initial, "");

The method invocation should be removed in both cases.

Anyone you would like to review specifically?

@timtebeek
@cjobinabo

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@rlsanders4 rlsanders4 self-assigned this Nov 7, 2024
Copy link
Contributor

@cjobinabo cjobinabo left a comment

Choose a reason for hiding this comment

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

Looks good, I just left a comment wonder if we can do some additional cleanup after the method removal


public void doX() {
Hashtable<String, String> env = new Hashtable<String, String>();
String initial = "java.naming.factory.initial";
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can do some additional cleanup here to remove these now unused variables. It looks like the org.openrewrite.staticanalysis.RemoveUnusedLocalVariables recipe could do this for us

@rlsanders4 rlsanders4 requested a review from cjobinabo November 7, 2024 22:35
@cjobinabo cjobinabo merged commit 7b6e820 into openrewrite:main Nov 7, 2024
2 checks passed
@rlsanders4 rlsanders4 removed the request for review from timtebeek November 8, 2024 15:11
@rlsanders4 rlsanders4 deleted the fixInitialContext branch November 8, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants