openrewrite / openrewrite/rewrite-static-analysis

Recipe to replace autoboxing with explicit `valueOf`

Open
#288 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

What problem are you trying to solve?

When using ParameterizedLogging, the output is not compatible in my IDE, since restriction is placed on autoboxing usage.
I wish I can apply another recipe that performs automatic wrapping of those primitives.
Note1: its fine if all applicable primitives are changed, since the entire project doesn't use autoboxing in the first place.
Note2: should be applicable to all primitives that can be autoboxed. i.e.: byte, short, int, long, float, double, char, boolean

What precondition(s) should be checked before applying this recipe?

Nil.

Describe the situation before applying the recipe

class A {
    void bar() {
        int i = 0;
        foo(i);
    }
    void foo(Integer bar) {
        // do something
    }
}

Describe the situation after applying the recipe

class A {
    void bar() {
        int i = 0;
        foo(Integer.valueOf(i));
    }
    void foo(Integer bar) {
        // do something
    }
}

Have you considered any alternatives or workarounds?

Unfortunately, I did not manage to fine any recipe, or rewrite tool, that supports this.
I was hoping IDE (Eclipse) can separate autoboxing and autounboxing criticality, but it doesn't allow me to do so.

Any additional context

Nil.

Are you interested in contributing this recipe to OpenRewrite?

Sure, if someone more experienced tells me its possible to create such a recipe.
I am afraid to dig deep into it, only to find out it is not possible with the current openrewrite concept.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by locating the existing OpenRewrite recipe entry points for Java transformations, then use the before-and-after examples to define the intended primitive-to-wrapper valueOf conversions and verify coverage for byte, short, int, long, float, double, char, and boolean.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.