openrewrite / openrewrite/rewrite-apache
Apache HttpClient 4 to 5 does not yet migrate `StringEntity.setContentEncoding()` to constructor argument
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 6
- Forks
- 19
- Avg merge
- 56m
- Merged PRs (30d)
- 3
Description
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:
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Spring Boot 3.1 migration command against the Java reproduction in this issue and inspect the Apache HttpClient 4-to-5 migration recipe that handles StringEntity. Add coverage for setContentEncoding("utf-8") and verify that the constructor receives the encoding and chunked=false, matching the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100