Intellij Plugin breaks method inlining and variable extraction from inside if condition
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- developer-experience, tooling
Research direction
Start with the Java reproduction in the issue and investigate the IntelliJ plugin's formatting interaction with method inlining and variable extraction inside an if condition. Reproduce the transformation with the plugin enabled and compare it with the disabled result; done means the refactoring no longer inserts an unnecessary if (true), reports an error, or leaves formatting broken.
Written by the indexing model from the issue text.
Description
Consider the following code and try inlining isEmpty2:
import java.util.Collection;
import java.util.List;
public class InliningWithJavaFormat {
static boolean isEmpty(Collection<?> c) {
return c == null || c.isEmpty();
}
static boolean isEmpty2(Collection<?> c) {
return isEmpty(c);
}
public static void main(String[] args){
var pojo = new MyPojo();
if (pojo != null && !isEmpty2(pojo.getCollection())) {
System.out.println("empty");
}
}
static class MyPojo {
Collection<String> getCollection() {
return List.of();
}
}
}
Not only does it fail (without reporting it), but it adds an additional if (true):
public static void main(String[] args){
var pojo = new MyPojo();
if (pojo != null && !isEmpty2(pojo.getCollection())) {
if (true) {
System.out.println("empty");
}
}
}
with the plugin disabled, it works:
public static void main(String[] args){
var pojo = new MyPojo();
if (pojo != null) {
Collection<?> c = pojo.getCollection();
if (!isEmpty(c)) {
System.out.println("empty");
}
}
}
(not the ideal result but at least it does not fail)
In addition, when I do that on my actual project I get an error notification from the plugin and the formatting gets broken:
(I did not try to reproduce this with an MRE, I guess it is a side effect of the first issue)
- Dominant language
- Java
- Stars
- 6.2k
- Forks
- 936
- Avg merge
- 6m
- Merged PRs (30d)
- 3
Getting set up
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.
More from google/google-java-format
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google/google-java-format#1094 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
google/google-java-format#1450 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
google/google-java-format#1439 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
google/google-java-format#1436 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
google/google-java-format#1428 · 4 comments ·
Maintainers usually reply within 1 day
All issues in google/google-java-format
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
nextcloud/notes-android#3367 ·
Maintainers usually reply within 1 day
-
Feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MuntashirAkon/AppManager#2058 ·
-
SarifLogger: artifactLocation.uri is not properly encoded for file names containing '#', '?', or '%'Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
checkstyle/checkstyle#21721 ·
Maintainers usually reply within 1 day