Repository: checkstyle/checkstyle

Problem statement:
Regression in IndentationCheck 8.40 regarding the white spaces needed in a second line of a try/resource declaration
https://checkstyle.org/config_misc.html#Indentation

$ javac Test.java

successful compilation

$ Test.java

```java
import java.io.*;

class Test {
    void test() {
        try (InputStreamReader reader = 
            new InputStreamReader(System.in)) {         // violation
                // try block...    
        } catch (Exception e) {
            // catch block...
        }
    }
}
```

$ config.java

```xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
      <module name="Indentation" />
    </module>
  </module>
</module>
```

Actual


$ java -jar checkstyle-8.40-all.jar -c config.xml t2.java

```
[ERROR] /home/abhishhek/playground/Test.java:6:13: 
  'operator new' has incorrect indentation level 12, expected level should be 16. [Indentation]
```

Expected

No violations

-----

#9071 seems to have caused an unexpected side effect in the default behavior of IndentationCheck.

The following line used to be valid with Checkstyle 8.37: https://github.com/xwiki/xwiki-platform/blob/xwiki-platform-13.0/xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/main/java/org/xwiki/icon/internal/DefaultIconSetManager.java#L129

and is now failing with

> 'new' has incorrect indentation level 16, expected level should be 20.

My configuration is https://github.com/xwiki/xwiki-commons/blob/xwiki-commons-13.0/xwiki-commons-tools/xwiki-commons-tool-verification-resources/src/main/resources/checkstyle.xml#L205


Hints:
@tmortagne Please edit your post to follow template https://checkstyle.org/report_issue.html#How_to_report_a_bug.3F
we did regression in xwiki code base that is not part of our execution :(  we use xwiki-common but problem is in xwiki-platform.

@Abhishek-kumar09 , can you take a look ?
@romani do you want me to try making the non regression job (not really sure where it is) build also xwiki-rendering and xwiki-platform ? It's much bigger than xwiki-commons so it will take longer to build.
job is at https://github.com/checkstyle/checkstyle/blob/master/.ci/wercker.sh#L97
but wercker is already over used.

we can think on extension at Travis like we do for another project:
https://github.com/checkstyle/checkstyle/blob/3d8b43445818246cd34ee97b3739dac75b10fae6/.ci/travis/travis.sh#L250

@tmortagne , you can send PR to make it happen it would be awesome, should be done in scope of different issue.

-----

as less efforts action we can add xwiki-platform to https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/projects-to-test-on.properties so we might see problem in regression testing.
> @tmortagne , you can send PR to make it happen it would be awesome

Sure, I will also try to give some info about how much longer it takes compared to xwiki-commons in the pull request description, and you can decide to apply it or not. Might not have the time to finish it before Monday with the FOSDEM this weekend but will see.

> should be done in scope of different issue.

Noted.
$ javac Test.java
```
successful compilation
```

$ Test.java
```java
import java.io.*;

class Test {
    void test() {
        try (InputStreamReader reader = 
            new InputStreamReader(System.in)) {         // violation
                // try block...    
        } catch (Exception e) {
            // catch block...
        }
    }
}
```

$ config.java
```bash
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
      <module name="Indentation" />
    </module>
  </module>
</module>

```
# Actual
$ java -jar checkstyle-8.40-all.jar -c config.xml t2.java 
```
[ERROR] /home/abhishhek/playground/Test.java:6:13: 'operator new' has incorrect indentation level 12, expected level should be 16. [Indentation]
```

# Expected
No violations


@tmortagne You can add these codes on your issue description to make it more clear. 
Here is the issue template for bug report: https://checkstyle.org/report_issue.html#How_to_report_a_bug.3F
OK thanks @Abhishek-kumar09 
> @tmortagne , you can send PR to make it happen it would be awesome, should be done in scope of different issue.

Issue: #9242
Pull request: #9243
I will be working on it.

Patch:
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/TryHandler.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/TryHandler.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/TryHandler.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/TryHandler.java
@@ -63,7 +63,8 @@ private DetailAST getTryResRparen() {
     public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child) {
         final IndentLevel result;
         if (child instanceof CatchHandler
-            || child instanceof FinallyHandler) {
+            || child instanceof FinallyHandler
+            || child instanceof NewHandler) {
             result = getIndent();
         }
         else {


Test patch:
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
@@ -2617,23 +2617,10 @@ public void testNewHandler() throws Exception {
         final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
         checkConfig.addAttribute("tabWidth", "4");
         final String[] expected = {
-            "8:1: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
-            "10:1: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
-            "13:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 8),
-            "15:1: " + getCheckMessage(MSG_ERROR, "new lparen", 0, 8),
-        };
-        verifyWarns(checkConfig, getPath("InputIndentationNewHandler.java"), expected);
-    }
-
-    @Test
-    public void testNewHandler2() throws Exception {
-        final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
-        checkConfig.addAttribute("tabWidth", "4");
-        final String[] expected = {
-            "8:1: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
-            "10:1: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
-            "13:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 8),
-            "15:1: " + getCheckMessage(MSG_ERROR, "new lparen", 0, 8),
+            "10:1: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
+            "12:1: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
+            "15:1: " + getCheckMessage(MSG_CHILD_ERROR, "new", 0, 8),
+            "17:1: " + getCheckMessage(MSG_ERROR, "new lparen", 0, 8),
         };
         verifyWarns(checkConfig, getPath("InputIndentationNewHandler.java"), expected);
     }
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationNewHandler.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationNewHandler.java
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationNewHandler.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationNewHandler.java
@@ -1,5 +1,7 @@
 package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0
 
+import java.io.InputStreamReader; //indent:0 exp:0
+
 public class InputIndentationNewHandler //indent:0 exp:0
 { //indent:0 exp:0
     public void test() { //indent:4 exp:4
@@ -13,5 +15,9 @@ public void test() { //indent:4 exp:4
 Integer("".indexOf("5")); //indent:0 exp:8 warn
         o = new Integer//indent:8 exp:8
 ("".indexOf("5")); //indent:0 exp:8 warn
+        try (InputStreamReader reader = //indent:8 exp:8
+            new InputStreamReader(System.in)) { //indent:12 exp:12
+        } catch (Exception e) { //indent:8 exp:8
+        } //indent:8 exp:8
     } //indent:4 exp:4
 } //indent:0 exp:0