1
2
3
4
5
6
7
8
9
10
11
12
13 package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod;
14
15 import java.util.function.Function;
16
17 public class InputJavadocMethodIgnoreThrowsOne {
18
19
20
21
22
23
24
25 private static int parsePositiveInt(String s) {
26 try {
27 int value = Integer.parseInt(s);
28 if (value <= 0) {
29 throw new NumberFormatException(value + " is negative/zero");
30 }
31 return value;
32 } catch (NumberFormatException ex) {
33
34 throw new IllegalArgumentException("Invalid number", ex);
35 } finally {
36
37 throw new IllegalStateException("Should never reach here");
38 }
39 }
40
41
42
43
44
45
46
47 private static void catchAndRethrow(Object o) {
48 try {
49 if (o == null) {
50 throw new IllegalArgumentException("null");
51 }
52 } catch (IllegalArgumentException ex) {
53
54 throw new IllegalArgumentException(ex.toString());
55 }
56 }
57
58
59
60
61
62
63
64 private static void catchAndRethrowSame(Object o) {
65 try {
66 if (o == null) {
67 throw new IllegalArgumentException("null");
68 }
69 } catch (IllegalArgumentException ex) {
70 throw ex;
71 }
72 }
73
74
75
76
77
78
79
80
81 private static void catchAndRethrowDifferent(Object o, int i) {
82 try {
83 float x = 1 / i;
84 } catch (RuntimeException ex) {
85 if (o == null) {
86 ex = new NullPointerException("");
87 }
88 throw ex;
89 }
90 }
91
92
93
94
95
96
97
98 private static Function<String, String> getTruncateFunction(int maxLength) {
99 return s -> {
100 if (s == null) {
101 throw new IllegalArgumentException("Cannot truncate null");
102 }
103 return s.length() > maxLength ? s.substring(0, maxLength) : s;
104 };
105 }
106
107 }