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

Incorrect comment indentation inside switch statements on case that is not first

Open
#1,155 1 comment 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
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
tooling

Research direction

Reproduce the report using the shown Test.java input and google-java-format 1.23.0, then compare the formatted output with the expected comment indentation. Trace the switch-statement formatting path and add regression coverage for a comment before a non-first case; done means the comment remains aligned as shown in the original input.

Written by the indexing model from the issue text.

Description

continuation of https://github.com/google/google-java-format/issues/1147

$ javac Test.java 
$ cat Test.java 
public class Test {
  public void check1(int x) {
    switch (x) {
      case 1:
        x = x + 1;
      /* fall-through*/ case 2:
        ;
      default:
        return;
    }
  }
}

$ java -jar google-java-format-1.23.0-all-deps.jar Test.java > TestUpdated.java
$ diff -u Test.java TestUpdated.java 
--- Test.java	2024-09-01 07:31:37.268757862 -0700
+++ TestUpdated.java	2024-09-01 07:31:54.329333795 -0700
@@ -3,7 +3,7 @@
     switch (x) {
       case 1:
         x = x + 1;
-      /* fall-through*/ case 2:
+        /* fall-through*/ case 2:
         ;
       default:
         return;

$ cat TestUpdated.java 
public class Test {
  public void check1(int x) {
    switch (x) {
      case 1:
        x = x + 1;
        /* fall-through*/ case 2:
        ;
      default:
        return;
    }
  }
}
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.