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

Do not change package when non-recursive #4447

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

timtebeek
Copy link
Contributor

Add unit test as reported via Slack by @BhavanaPidapa; update precondition to evaluate recursive boolean for package declaration too.

@timtebeek timtebeek added the bug Something isn't working label Aug 26, 2024
@timtebeek timtebeek requested a review from cjobinabo August 26, 2024 21:53
@timtebeek timtebeek self-assigned this Aug 26, 2024
anandfresh

This comment was marked as outdated.

@BhavanaPidapa
Copy link

BhavanaPidapa commented Aug 27, 2024

Hey Tim,

Below is the test case where changes to com.sun.net.ssl.internal.* are not expected. Please refer to the attached screenshot.

@Test
void excludePackageTest() {
    //language=java
    rewriteRun(
      spec -> spec.recipe(new ChangePackage(
        "com.sun.net.ssl",
        "javax.net.ssl",
        false
      )),
      java(
        """
          package com.test;
          import com.sun.net.ssl.internal.*;
          import com.sun.net.ssl.HostnameVerifier;
          class Test {
           public com.sun.net.ssl.HostnameVerifier hv;
              void exampleMethod() {
              }
          }
          """,
        """
          package com.test;
          import com.sun.net.ssl.internal.*;
          import javax.net.ssl.HostnameVerifier;
          class Test {
           public javax.net.ssl.HostnameVerifier hv;
              void exampleMethod() {
              }
          }
          """
      )
    );
}

image

@timtebeek timtebeek marked this pull request as draft January 22, 2025 13:47
Copy link
Contributor

@github-actions github-actions bot left a 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/src/test/java/org/openrewrite/java/internal/parser/TypeTableTest.java
    • lines 51-51
    • lines 67-68
    • lines 92-93
    • lines 140-140

@timtebeek
Copy link
Contributor Author

timtebeek commented Jan 22, 2025

Capturing the nonRecursiveShouldIgnoreNestedWildcardImport test failure output

diff --git a/Foo.java b/Foo.java	
index 562edaa..d960c46 100644	
--- a/Foo.java	
+++ b/Foo.java	
@@ -1,4 +1,4 @@ 	
-import com.sun.net.ssl.internal.*;	
+import javax.net.ssl.internal.*;	
 import javax.net.ssl.HostnameVerifier;	
 class Foo {	
     javax.net.ssl.HostnameVerifier hv;	

@timtebeek
Copy link
Contributor Author

This is an interesting case: we first and separate evaluate a precondition to determine if we need further changes; that precondition resolves to true due to the presence of com.sun.net.ssl.HostnameVerifier; then we unconditionally change any package references in the actual visitor, whereas we should probably still take into account there whether we should do so recursively.

@knutwannheden
Copy link
Contributor

knutwannheden commented Jan 24, 2025

Maybe fixed by #4942? Not sure, as the work I did was for YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants