Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

comment after class that has implements cause wrong indentation

Open
#1,126 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java
Domain
tooling

Research direction

Start by reproducing the issue with the provided Test.java input and google-java-format-1.23.0-all-deps.jar command. Trace the formatter path handling a trailing comment after the class declaration, then add coverage for this example and verify that implements is indented by four spaces and the original structure is preserved.

Written by the indexing model from the issue text.

Description

Indention of implements becomes 0, but should be +4 (as it is line wrap) from 0, so 4.

$ cat Test.java 
/** Tetsing. */
public class Test // comment
    implements Runnable, Cloneable {

}

$ java -jar google-java-format-1.23.0-all-deps.jar Test.java > TestUpdated.java

$ diff -u Test.java TestUpdated.java 
--- Test.java	2024-07-31 06:29:22.086232824 -0700
+++ TestUpdated.java	2024-07-31 06:33:39.001224613 -0700
@@ -1,5 +1,3 @@
 /** Tetsing. */
 public class Test // comment
-    implements Runnable, Cloneable {
-
-}
+implements Runnable, Cloneable {}

$ cat TestUpdated.java 
/** Tetsing. */
public class Test // comment
implements Runnable, Cloneable {}

Workaround is to remove trailing comment
but better to handle/format it eventually in proper way.

Dominant language
Java
Stars
6.2k
Forks
936
Avg merge
6m
Merged PRs (30d)
3

Getting set up

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.

More from google/google-java-format

All issues in google/google-java-format

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.