openrewrite / openrewrite/rewrite-static-analysis

Unused assignments should be removed

Open
#63 2 comments 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

see: https://rules.sonarsource.com/java/tag/unused/RSPEC-1854

A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it’s not an error, it is at best a waste of resources. Therefore all calculated values should be used.

Note, that this problem, "dead code analysis", among others, is one of the posterchild problems solved by representing the tree as a Control Flow Graph.

See also: https://www.cs.utexas.edu/~pingali/CS380C/2020/lectures/CFG.pdf

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 by reading the linked SonarSource RSPEC-1854 rule and the referenced control-flow-graph lecture. Then inspect this repository’s existing static-analysis recipes to determine the intended entry point and tests; done means unused local assignments are identified and removed without affecting values that are subsequently read.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.