openrewrite / openrewrite/rewrite-static-analysis

`InlineVariable` to handle more complex expressions too

Open
#803 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What version of OpenRewrite are you using?

I am using
id 'org.openrewrite.rewrite' version '7.22.0' apply false
org.openrewrite.recipe:rewrite-static-analysis:2.23.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'org.openrewrite.rewrite'

dependencies {
    rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.23.0')
}

rewrite {
    activeRecipe('org.apache.kafka.openrewrite.SanityCheck')
    configFile = project.getRootProject().file("${rootDir}/config/sanity.yml")
    setExportDatatables(true)
    setFailOnDryRunResults(true)
}

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

    private int nextValue(String topic) {
        AtomicInteger counter = topicCounterMap.computeIfAbsent(topic, k -> new AtomicInteger(0));
        return counter.getAndIncrement();
    }

What did you expect to see?

    private int nextValue(String topic) {
        return topicCounterMap.computeIfAbsent(topic, k -> new AtomicInteger(0)).getAndIncrement();
    }

What did you see instead?

    private int nextValue(String topic) {
        AtomicInteger counter = topicCounterMap.computeIfAbsent(topic, k -> new AtomicInteger(0));
        return counter.getAndIncrement();
    }

PS: please dont be the new checkstyle caring more and actually only about their bug-template instead of the bug.

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

Start with the InlineVariable recipe and reproduce the issue using the provided nextValue example. Compare the current result with the expected chained computeIfAbsent(...).getAndIncrement() form; done means the more complex expression is inlined without changing behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.