1
2
3
4
5
6
7
8
9
10
11
12
13 package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod;
14
15
16
17 import java.io.BufferedReader;
18 import java.io.FileReader;
19 import java.io.IOException;
20 import java.util.Scanner;
21 import java.util.function.Function;
22
23 public class InputJavadocMethodIgnoreThrows {
24
25
26
27
28
29
30
31 private static int parsePositiveInt(String s) {
32 try {
33 int value = Integer.parseInt(s);
34 if (value <= 0) {
35 throw new NumberFormatException(value + " is negative/zero");
36 }
37 return value;
38 } catch (NumberFormatException ex) {
39
40 throw new IllegalArgumentException("Invalid number", ex);
41 } finally {
42
43 throw new IllegalStateException("Should never reach here");
44 }
45 }
46
47
48
49
50
51
52
53 private static void catchAndRethrow(Object o) {
54 try {
55 if (o == null) {
56 throw new IllegalArgumentException("null");
57 }
58 } catch (IllegalArgumentException ex) {
59
60 throw new IllegalArgumentException(ex.toString());
61 }
62 }
63
64
65
66
67
68
69
70 private static void catchAndRethrowSame(Object o) {
71 try {
72 if (o == null) {
73 throw new IllegalArgumentException("null");
74 }
75 } catch (IllegalArgumentException ex) {
76 throw ex;
77 }
78 }
79
80
81
82
83
84
85
86
87 private static void catchAndRethrowDifferent(Object o, int i) {
88 try {
89 float x = 1 / i;
90 } catch (RuntimeException ex) {
91 if (o == null) {
92 ex = new NullPointerException("");
93 }
94 throw ex;
95 }
96 }
97
98
99
100
101
102
103
104 private static Function<String, String> getTruncateFunction(int maxLength) {
105 return s -> {
106 if (s == null) {
107 throw new IllegalArgumentException("Cannot truncate null");
108 }
109 return s.length() > maxLength ? s.substring(0, maxLength) : s;
110 };
111 }
112
113
114
115
116
117
118 private static void ignoreTryWithResources(String input) {
119 try (BufferedReader in = new BufferedReader(new FileReader(input))) {
120 String s = in.readLine();
121 System.out.println(s);
122 if (s.length() == 0) {
123
124 throw new IllegalArgumentException("empty input");
125 }
126 else {
127 throw new IOException();
128 }
129 } catch (IOException e) {
130 System.out.println("Error reading file");
131 }
132 }
133
134
135
136
137 private static void keepTryWithoutCatch() {
138 try (Scanner sc = new Scanner(System.in)) {
139 if (sc.nextInt() <= 0) {
140
141 throw new IllegalArgumentException("");
142 }
143 }
144 }
145
146
147
148
149
150
151 void dfs(String str) {
152 class DFS {
153 void neverCalled() {
154 throw new IllegalStateException("");
155 }
156
157 void dfs(String str) {
158 if (str != null) {
159 dfs(str.toLowerCase());
160 System.out.println(str);
161 dfs(str.toUpperCase());
162 }
163 }
164 }
165 new DFS().dfs(str);
166 }
167
168
169
170
171
172
173 Runnable ignoreAnonClasses() {
174 return new Runnable() {
175 @Override
176 public void run() {
177 throw new UnsupportedOperationException("");
178 }
179 };
180 }
181
182
183
184
185
186
187
188 Function<String, Integer> lambdaInCatchBlock(String s) {
189 try {
190 int value = Integer.parseInt(s);
191 if (value <= 0) {
192 throw new NumberFormatException(value + " is negative/zero");
193 }
194 return x -> value;
195 } catch (NumberFormatException ex) {
196 if (s.length() == 1) {
197
198 throw new IllegalArgumentException("Invalid number", ex);
199 }
200 return x -> {
201 throw new UnsupportedOperationException("");
202 };
203 }
204 }
205
206 }