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

Apache HttpClient 4 to 5 does not yet migrate StringEntity.setContentEncoding() to constructor argument #54

Open
FieteO opened this issue Jan 17, 2025 · 3 comments
Labels
bug Something isn't working recipe

Comments

@FieteO
Copy link

FieteO commented Jan 17, 2025

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v2.0.0

How are you running OpenRewrite?

I am running the spring boot 3.1 migration via the command line:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1 -Drewrite.exportDatatables=true

What is the smallest, simplest way to reproduce the problem?

import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

class A {
        void foo() {
                StringEntity se = new StringEntity("", ContentType.APPLICATION_JSON);
                se.setContentEncoding("utf-8");
        }
}

What did you expect to see?

import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.StringEntity;

class A {
        void foo() {
                StringEntity se = new StringEntity("", ContentType.APPLICATION_JSON, "utf-8", false);
        }
}

Note that the fourth constructor parameter (chunked) of StringEntity is set to false based on the default value that is used by the smaller constructor:

Image

What did you see instead?

setContentEncoding is not replaced with setting the value via the constructor.

import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.StringEntity;

class A {
        void foo(String bar) {
                StringEntity se = new StringEntity("", ContentType.APPLICATION_JSON);
                se.setContentEncoding("utf-8");
        }
}

Are you interested in contributing a fix to OpenRewrite?

No

@FieteO FieteO added the bug Something isn't working label Jan 17, 2025
@FieteO FieteO changed the title setContentEncoding is not migrated StringEntity.setContentEncoding is not migrated Jan 17, 2025
@FieteO FieteO changed the title StringEntity.setContentEncoding is not migrated StringEntity.setContentEncoding() is not migrated Jan 17, 2025
@timtebeek
Copy link
Contributor

Do note that we have a recipe step that should make the necessary package change here at least:

- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.http.entity
newPackageName: org.apache.hc.core5.http.io.entity

I wonder if there might be any other issues why you're not seeing any changes at all.

@timtebeek timtebeek added the question Further information is requested label Jan 17, 2025
@FieteO
Copy link
Author

FieteO commented Jan 17, 2025

Oh I am sorry, it's always hard not to forget something when extrapolating from the "real" example to what is reported in such a ticket.
The imports are indeed changed, but the setContentEncoding remains untouched. I have updated the ticket description now.

@timtebeek
Copy link
Contributor

timtebeek commented Jan 17, 2025

Ah thanks! That narrows this down indeed; looks like that setter argument should be moved to the constructor then? That would likely require a new recipe to remove that method invocation and move the argument into the constructor.

@timtebeek timtebeek removed the question Further information is requested label Jan 17, 2025
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jan 17, 2025
@timtebeek timtebeek changed the title StringEntity.setContentEncoding() is not migrated Apache HttpClient 4 to 5 does not yet migrate StringEntity.setContentEncoding() to constructor argument Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working recipe
Projects
Status: Backlog
Development

No branches or pull requests

2 participants