Repository navigation
Closed
Description
The source code in this example has to be formatted two times until it does not change anymore.
Used command line:
java -jar google-java-format-1.25.2-all-deps.jar -r --skip-removing-unused-imports --skip-reflowing-long-strings <path_to>/Test.java
Original file com/test/Test.java
package com.test;
import java.util.Map;
import java.util.TreeMap;
public class Test {
public static Map<String, String> test(Map<String, String> structure) {
structure
.entrySet()
.stream()
.filter(e -> e.getValue().isEmpty())
.forEach(e -> {
if (structure.containsValue(e.getKey())) { // The quick brown fox jumps over the lazy dog, and again the quick brown fox jumps over the lazy dog
e.setValue(e.getKey());
}
});
return new TreeMap<>(structure);
}
}
After formatting the first time:
package com.test;
import java.util.Map;
import java.util.TreeMap;
public class Test {
public static Map<String, String> test(Map<String, String> structure) {
structure.entrySet().stream()
.filter(e -> e.getValue().isEmpty())
.forEach(
e -> {
if (structure.containsValue(
e
.getKey())) { // The quick brown fox jumps over the lazy dog, and again the
// quick brown fox jumps over the lazy dog
e.setValue(e.getKey());
}
});
return new TreeMap<>(structure);
}
}
After formatting the second time:
package com.test;
import java.util.Map;
import java.util.TreeMap;
public class Test {
public static Map<String, String> test(Map<String, String> structure) {
structure.entrySet().stream()
.filter(e -> e.getValue().isEmpty())
.forEach(
e -> {
if (structure.containsValue(
e.getKey())) { // The quick brown fox jumps over the lazy dog, and again the
// quick brown fox jumps over the lazy dog
e.setValue(e.getKey());
}
});
return new TreeMap<>(structure);
}
}
There are no changes after formatting the file again.
I admit that the comment is placed at an unusual location.
There is no issue if the comment appears in a separate line in front of the if-statement, or in the next line after the opening block {.
Metadata
Metadata
Assignees
Labels
No labels
Activity
cushon commentedon Dec 19, 2024
Thanks for the report, I agree the output should be stable. I think this specific issue with line comments is the same as #211