View Javadoc
1   /*
2   RequireThis
3   checkFields = (default)true
4   checkMethods = (default)true
5   validateOnlyOverlapping = false
6   
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
11  
12  public class InputRequireThisCatchVariables extends Thread {
13      private Throwable ex;
14  
15      public InputRequireThisCatchVariables(Throwable ex) {
16          this.ex = ex;
17      }
18  
19      @Override
20      public void run() {
21          if (this.ex != null) {
22              try {
23                  exceptional(this.ex);
24              }
25              catch (RuntimeException ex) {
26                  if (ex == this.ex) {
27                      debug("Expected exception thrown", ex);
28                  }
29                  else {
30                      ex.printStackTrace();
31                  }
32              }
33              catch (Error err) {
34                  if (err == this.ex) {
35                      debug("Expected exception thrown", err);
36                  }
37                  else {
38                      ex.printStackTrace(); // violation '.* variable 'ex' needs "this.".'
39                  }
40              }
41              catch (Throwable ex) {
42                  ex.printStackTrace();
43              }
44          }
45      }
46  
47      private static void exceptional(Throwable ex) {}
48      private static void debug(String message, Throwable err) {}
49  
50      int baseline;
51      public int getBaseline() {
52          int baseline = 12;
53          final int placement = 3;
54          switch (placement) {
55              case 3:
56                  baseline = 3 + baseline;
57                  return baseline;
58          }
59          return -1;
60      }
61  }