Repository: checkstyle/checkstyle (2026-03-27T20:06:36Z)

Issue:
Improve examples of IndentationCheck
Improve examples of IndentationCheck
To show different behavior after each property got special value.

We merged bulk [update](https://github.com/checkstyle/checkstyle/pull/19402) to let all properties be in examples, but all examples are same, not clear how property affects validation 


Discussion:
Hello @romani I'm on it.
Hi @romani,

I noticed that someone has already expressed interest in this issue, but I wanted to mention that I had actually started exploring and working on this a couple of days ago.

I’ve been looking into improving the IndentationCheck examples to better reflect how different property values affect validation behavior.

Please let me know if I can continue and raise a PR for this.

Thanks!
Hello @romani as @developer4949-code already send pr so, should I leave this issue or continue.
Non of PR are good, can we split update in each example in separate PR ? To do progress and avoid conflicts 
> Non of PR are good, can we split update in each example in separate PR ? To do progress and avoid conflicts

@romani Yes..!
The following properties still lack a dedicated example:

- `basicOffset`
- `braceAdjustment`
- `arrayInitIndent`
- `lineWrappingIndentation`
- `throwsIndent`

Could we update the issue description to list each of these properties as a separate task? That way contributors can self-assign individual properties and raise focused PRs without stepping on each other. It would also make it easier to track progress per property directly on the issue.
Hi @romani, thanks for suggesting the split-PR approach. 

I'd like to work on improving the example for the **`arrayInitIndent` property**. 
I'll create a focused PR demonstrating how this property affects array initialization 
indentation behavior - showing both violations and correct indentation patterns.

I'll follow the pattern of the existing PRs and keep it isolated.
Hi @romani,

I have created a focused PR for the `arrayInitIndent` property examples as suggested.

PR: https://github.com/checkstyle/checkstyle/pull/19470

Please let me know if any changes are needed.
Fix is merged 



Patch:
diff --git a/src/site/xdoc/checks/misc/indentation.xml b/src/site/xdoc/checks/misc/indentation.xml
index 1408c0d468c4..199f193d9c9d 100644
--- a/src/site/xdoc/checks/misc/indentation.xml
+++ b/src/site/xdoc/checks/misc/indentation.xml
@@ -341,6 +341,70 @@ class Example4 {
         }
     }
 }
+</code></pre></div><hr class="example-separator"/>
+        <p id="Example7-config">
+          To configure the check with custom throwsIndent (8 spaces instead of default 4):
+        </p>
+        <div class="wrapper"><pre class="prettyprint"><code class="language-xml">
+&lt;module name="Checker"&gt;
+  &lt;module name="TreeWalker"&gt;
+    &lt;module name="Indentation"&gt;
+      &lt;property name="throwsIndent" value="8"/&gt;
+    &lt;/module&gt;
+  &lt;/module&gt;
+&lt;/module&gt;
+</code></pre></div>
+        <p id="Example7-code">
+          Example of code with throwsIndent set to 8.
+          Method 'processValues' has throws on a new line with only 4-space indent,
+          which violates the configured 8-space throwsIndent.
+          Method 'demonstrateSwitch' has throws on a new line with correct 8-space indent:
+        </p>
+        <div class="wrapper"><pre class="prettyprint"><code class="language-java">
+class Example7 {
+    String field = "example";                  // basicOffset
+    int[] values = {                           // basicOffset
+        10,
+        20,
+        30
+    };
+
+    void processValues()
+        throws Exception { // violation, ''throws' has incorrect indentation'
+        handleValue("Test String", 42);          // basicOffset
+    }
+
+    void handleValue(String aFooString,
+                     int aFooInt) {             // indent:8 ; expected: &gt; 4;
+
+        boolean cond1,cond2,cond3,cond4,cond5,cond6;
+        cond1=cond2=cond3=cond4=cond5=cond6=false;
+
+        if (cond1
+            || cond2) {
+            field = field.toUpperCase()
+                .concat(" TASK");
+        }
+
+        if ((cond1 &amp;&amp; cond2)
+                || (cond3 &amp;&amp; cond4)          // ok, lineWrappingIndentation
+                || !(cond5 &amp;&amp; cond6)) {      // ok, lineWrappingIndentation
+            field.toUpperCase()
+                 .concat(" TASK")             // ok, lineWrappingIndentation
+                 .chars().forEach(c -&gt; {      // ok, lineWrappingIndentation
+                     System.out.println((char) c);
+                 });
+        }
+    }
+
+    void demonstrateSwitch()
+            throws Exception {               // ok, throwsIndent is 8
+        switch (field) {
+            case "EXAMPLE": processValues();                        // caseIndent
+            case "COMPLETED": handleValue("Completed Case", 456);   // caseIndent
+        }
+    }
+}
 </code></pre></div>
       </subsection>
 
diff --git a/src/site/xdoc/checks/misc/indentation.xml.template b/src/site/xdoc/checks/misc/indentation.xml.template
index fdc74c98d97e..999c5a871fdd 100644
--- a/src/site/xdoc/checks/misc/indentation.xml.template
+++ b/src/site/xdoc/checks/misc/indentation.xml.template
@@ -88,6 +88,25 @@
           <param name="path"
                  value="resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example4.java"/>
           <param name="type" value="code"/>
+        </macro><hr class="example-separator"/>
+        <p id="Example7-config">
+          To configure the check with custom throwsIndent (8 spaces instead of default 4):
+        </p>
+        <macro name="example">
+          <param name="path"
+                 value="resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example7.java"/>
+          <param name="type" value="config"/>
+        </macro>
+        <p id="Example7-code">
+          Example of code with throwsIndent set to 8.
+          Method 'processValues' has throws on a new line with only 4-space indent,
+          which violates the configured 8-space throwsIndent.
+          Method 'demonstrateSwitch' has throws on a new line with correct 8-space indent:
+        </p>
+        <macro name="example">
+          <param name="path"
+                 value="resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example7.java"/>
+          <param name="type" value="code"/>
         </macro>
       </subsection>
 
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example7.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example7.java
index 633a5972536f..d5fd937bdeee 100644
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example7.java
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/Example7.java
@@ -20,7 +20,7 @@ class Example7 {
     };
 
     void processValues()
-            throws Exception {                 // ok, throwsIndent
+        throws Exception { // violation, ''throws' has incorrect indentation'
         handleValue("Test String", 42);          // basicOffset
     }
 
@@ -48,7 +48,7 @@ void handleValue(String aFooString,
     }
 
     void demonstrateSwitch()
-            throws Exception {               // ok, throwsIndent
+            throws Exception {               // ok, throwsIndent is 8
         switch (field) {
             case "EXAMPLE": processValues();                        // caseIndent
             case "COMPLETED": handleValue("Completed Case", 456);   // caseIndent


Test patch:
diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckExamplesTest.java
index 714a649beea2..1559a6f22e1a 100644
--- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckExamplesTest.java
+++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckExamplesTest.java
@@ -76,7 +76,9 @@ public void testExample6() throws Exception {
 
     @Test
     public void testExample7() throws Exception {
-        final String[] expected = {};
+        final String[] expected = {
+            "23:9: " + getCheckMessage(MSG_ERROR, "throws", 8, 12),
+        };
         verifyWithInlineConfigParser(getPath("Example7.java"), expected);
     }