1
2
3
4
5
6
7
8
9
10 package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;
11
12 import java.util.*;
13
14 public class InputRequireThisValidateOnlyOverlappingFalse {
15
16 private static String fieldStatic = "fieldStatic";
17
18 private final long fieldFinal1;
19 private final long fieldFinal2;
20 private final BitSet fieldFinal3;
21
22 private String field1;
23 private String field2;
24 private String field3 = "some string";
25 private boolean booleanField;
26 private int intField;
27
28 public InputRequireThisValidateOnlyOverlappingFalse(String field1) {
29 field1 = field1;
30 fieldFinal1 = 0;
31 fieldFinal2 = 0;
32 fieldFinal3 = new BitSet();
33 }
34
35 public InputRequireThisValidateOnlyOverlappingFalse(long value) {
36 fieldFinal1 = value;
37 fieldFinal2 = 0;
38 fieldFinal3 = new BitSet();
39 }
40
41 public InputRequireThisValidateOnlyOverlappingFalse() {
42 fieldFinal1 = 0;
43 long fieldFinal2 = 0L;
44 fieldFinal2 = 1L;
45 this.fieldFinal2 = fieldFinal2;
46 fieldFinal3 = new BitSet();
47 }
48
49 public InputRequireThisValidateOnlyOverlappingFalse(String name, long id) {
50 fieldFinal1 = 0;
51 long field1 = 0L;
52 field1 = field1;
53 this.fieldFinal2 = 1L;
54 fieldFinal3 = new BitSet();
55 }
56
57 public InputRequireThisValidateOnlyOverlappingFalse(int param) {
58 fieldFinal2 = 0L;
59 fieldFinal3 = new BitSet();
60 long fieldFinal1 = 1L;
61 try {
62 fieldFinal1 = 2L;
63 }
64 catch (Exception ex) {}
65 this.fieldFinal1 = fieldFinal1;
66 }
67
68 public InputRequireThisValidateOnlyOverlappingFalse(BitSet fieldFinal3) {
69 fieldFinal1 = 1L;
70 fieldFinal2 = 0L;
71 fieldFinal3 = new BitSet();
72 if (true) {
73 fieldFinal3 = (BitSet) fieldFinal3.clone();
74 }
75 this.fieldFinal3 = fieldFinal3;
76 }
77
78 void foo1(String methodParam) {
79 methodParam = methodParam;
80 }
81
82 void foo2() {
83 String localVar = "values";
84 localVar = localVar;
85 }
86
87 void foo3() {
88 String field1 = "values";
89 field1 = field1;
90 }
91
92 void foo4(String methodParam) {
93 fieldStatic = methodParam;
94 }
95
96 void foo5(String methodParam) {
97 methodParam = methodParam + "string";
98 }
99
100 void foo6(String field1) {
101 field1 = this.field1 + field1;
102 this.field1 = field1 + this.field1;
103 field1 = field1 + this.field1;
104 field1 = this.field1 + this.field1;
105 this.field1 = this.field1 + this.field1;
106 this.field1 = this.field1 + field1;
107 field1 += field1;
108 }
109
110 String addSuffixToParameter(String methodParam) {
111 return methodParam += "suffix";
112 }
113
114 String addSuf2F(String field1) {
115 return field1 += "suffix";
116 }
117
118 String addSuffixToThisField(String field1) {
119 return this.field1 += "suffix";
120 }
121
122 static void foo7(String fieldStatic) {
123
124 fieldStatic = fieldStatic;
125 }
126
127 void foo8(Long field1) {
128 field1 += field1;
129 }
130
131 void foo9(Long fieldFinal1) {
132
133 fieldFinal1 += fieldFinal1;
134 }
135
136 void method1() {
137 field1 = "2";
138 }
139
140 void method2() {
141 method1() ;
142 }
143
144 void method3() {
145 staticFoo();
146 staticTwoArgs("message", "arg");
147 staticTwoArgs("message", 1);
148 this.method1() ;
149 }
150
151 static void staticFoo() { }
152
153 static void foo10() {
154 staticFoo();
155 staticTwoArgs("message", "arg");
156 }
157
158
159
160 static void staticTwoArgs(String message1, String argument) {}
161
162 void staticTwoArgs(String message1, int argument) {}
163
164 static void foo16() {
165 long fieldFinal1 = 5L;
166
167 fieldFinal1 = 11L;
168 }
169
170 static void foo17() {
171 String fieldStatic = "";
172
173 fieldStatic = "Hello, World!";
174 }
175
176 InputRequireThisValidateOnlyOverlappingFalse(boolean flag) {
177 fieldFinal1 = 0L;
178 fieldFinal2 = 0L;
179 fieldFinal3 = new BitSet();
180 long field1 = 1L;
181 field1 = field1;
182 }
183
184 InputRequireThisValidateOnlyOverlappingFalse(boolean flag, String name) {
185 fieldFinal1 = 0L;
186 fieldFinal2 = 0L;
187 fieldFinal3 = new BitSet();
188 long field1 = 1L;
189 field1 = field1;
190 return;
191 }
192
193 void foo18() {
194 field1 = "Hello";
195 }
196
197 void foo19(String field1) {
198 field1 = "Hello";
199 }
200
201 void foo20() {
202 boolean foo21 = this.foo21("");
203 if (foo21) {
204
205 }
206 }
207
208 boolean foo21(String s) {
209 return true;
210 }
211
212 void foo22() {
213 long fieldFinal1 = 1L;
214
215 fieldFinal1 = fieldFinal1;
216 }
217
218 void foo23() {
219 field1 = "Hello!";
220 }
221
222 void foo24() {
223 String field1 = "Hello";
224 field1 = "Java";
225 this.booleanField = true;
226 this.booleanField = booleanField;
227 }
228
229 void foo25() {
230 try {
231 if (true) {
232 String field1 = "Hello, World!";
233 if (true) {
234 field1 = new String();
235 }
236 else {
237 field1 += field1;
238 }
239 }
240 }
241 catch (Exception ex) {
242
243 }
244 }
245
246 void foo26(String field1) {
247 field1 = field1.replace('/', '*');
248 }
249
250 void foo27() {
251 int intField = -1;
252 if (intField == -1) {
253 intField = 20;
254 }
255 else {
256 intField = this.intField / 100;
257 }
258 }
259
260 void foo28() {
261 boolean booleanField = true;
262 booleanField = !booleanField;
263 }
264
265 static void foo29(String field1) {
266
267 field1 = true ? "field1" : field1;
268 }
269
270 void foo30(String field1) {
271 field1 = true ? "field1" : field1;
272 }
273
274 void foo31(String field1) {
275 field1 = this.field1;
276 }
277
278 String foo32(String field1) {
279 field1 = addSuf2F(field1);
280 return field1;
281 }
282
283 String foo33(String field1 ) {
284 field1 = addSuf2F(field1);
285 return "New String";
286 }
287
288 String foo34(String field1) {
289 field1 = field1.replace('A', 'B');
290 if (field1.contains("C")) {
291 return field1;
292 }
293 else {
294 return field1 + 'C';
295 }
296 }
297
298 String foo35() {
299 String field1 = "values";
300 field1 = field1;
301 return field1;
302 }
303
304 void foo36(String field1) {
305 field1 = field1.replace('/', '*');
306 field1 = this.field1;
307 }
308
309 String foo37(String field1) {
310 field1 += "suffix";
311 return "New string";
312 }
313
314 static void foo38() {
315
316 fieldStatic = "";
317 }
318
319 static void foo39() {
320 boolean booleanField = true;
321
322 booleanField = !booleanField;
323 }
324
325 static void foo40() {
326 try {
327 boolean booleanField = true;
328
329 booleanField = !booleanField;
330 }
331 catch (Exception e) {}
332 }
333
334 static {
335
336 fieldStatic = "";
337 }
338
339 {
340
341
342
343
344
345 }
346
347 {
348 String field1 = "";
349 field1 = field1;
350 }
351
352 static {
353 fieldStatic = "";
354 String field1 = "";
355
356 field1 = field1;
357 }
358
359 void foo41(long fieldFinal1) {
360
361 fieldFinal1 = fieldFinal1;
362 }
363
364 void foo42(String fieldStatic) {
365 this.fieldStatic = fieldStatic;
366 }
367
368 void foo43(String fieldStatic) {
369 fieldStatic = fieldStatic;
370 }
371
372 void foo44(String fieldStatic) {
373 fieldStatic = this.fieldStatic;
374 }
375
376 private String action;
377
378 public String getAction() {
379 return this.action;
380 }
381
382 public String foo45() {
383 String action = getAction();
384 if (true) {
385 return processAction("action");
386 }
387 else if (action.endsWith("/")) {
388 if (action.startsWith("/")) {
389 action = "" + action;
390 }
391 }
392 action = "action";
393 return processAction(action);
394 }
395
396 private String processAction(String action) {
397 return "";
398 }
399
400 public InputRequireThisValidateOnlyOverlappingFalse(long fieldFinal1, long fieldFinal2,
401 BitSet fieldFinal3, boolean booleanField) {
402 this.fieldFinal1 = fieldFinal1;
403 this.fieldFinal2 = fieldFinal2;
404 this.fieldFinal3 = fieldFinal3;
405
406 booleanField = this.booleanField;
407 if (booleanField) {
408 booleanField = "Hello, World!".equals("Hello, Checkstyle!");
409 }
410
411 this.booleanField = booleanField;
412 }
413
414 void foo46(boolean booleanField) {
415 booleanField = this.booleanField;
416 if (booleanField) {
417 booleanField = "Hello, World!".equals("Hello, Checkstyle!");
418 }
419
420 this.booleanField = booleanField;
421 }
422
423 static void foo47(String fieldStatic) {
424 fieldStatic = "Andrei";
425 }
426
427 void foo48(long fieldFinal1) {
428 fieldFinal1 = 1L;
429 }
430
431 private boolean foo49(boolean booleanField) {
432 boolean suppressionSourceExists = true;
433 try {
434
435 }
436 catch (Exception ex) {
437 suppressionSourceExists = false;
438 }
439 finally {
440 if (booleanField) {
441 try {
442 }
443 catch (Exception ignored) {
444 this.booleanField = false;
445 }
446 }
447 }
448 return suppressionSourceExists;
449 }
450
451 void foo50(String fieldStatic) {
452 fieldStatic = fieldStatic;
453 }
454
455 void foo51(String methodParam) {
456 fieldStatic = methodParam;
457 }
458
459 void foo52(String fieldStatic) {
460 fieldStatic += fieldStatic;
461 }
462
463 void foo53(String fieldStatic) {
464 fieldStatic += fieldStatic;
465 }
466
467 void foo54(String methodParam) {
468 fieldStatic += methodParam;
469 }
470
471 void foo55(String methodParam) {
472 fieldStatic += fieldStatic;
473 }
474
475 void foo56(boolean booleanField) { booleanField = this.booleanField; }
476
477 boolean foo57(boolean booleanField) { booleanField = !booleanField; return booleanField; }
478 }
479 class Issue6264 {
480 private final String hashCode;
481
482 Issue6264() {
483 this.hashCode = new String();
484 }
485
486 private void hashCodeMethod(String param) {
487 hashCode();
488 }
489 }
490 class Issue7306 {
491 List<String> add = new ArrayList<>();
492 List<String> singletonList = new ArrayList<>();
493
494 void someMethod() {
495 List<String> test = new ArrayList<>();
496 test.forEach(this.add::add);
497 test.forEach(test::add);
498 test.forEach(Collections::singletonList);
499 test.forEach(add::add);
500 }
501 }
502 class AnotherOverlappingFalse {
503 private String name;
504
505 public void bind() {
506 new Object() {
507 @Override
508 public String toString() {
509 String name = null;
510
511 if ( true ) {
512 name = String.format(Locale.US, name);
513 }
514
515 return name;
516 }
517 };
518 }
519 }