1
2
3
4
5
6 package com.puppycrawl.tools.checkstyle.checks.coding.unnecessarynullcheckwithinstanceof;
7
8 public class InputUnnecessaryNullCheckWithInstanceOfTryCatch {
9 public void basicTryCatch(Object obj) {
10 try {
11 if (obj != null && obj instanceof String) {
12 String str = (String) obj;
13 }
14 } catch (Exception e) {}
15 }
16 public void catchBlockCheck(Object obj) {
17
18 try {
19 String str = (String) obj;
20 }
21 catch (Exception e) {
22
23 if (e != null && e instanceof RuntimeException) {
24 throw (RuntimeException) e;
25 }
26 }
27 }
28 public void finallyBlockCheck(Object obj) {
29 try {
30 String str = (String) obj;
31 } finally {
32
33 if (obj != null && obj instanceof AutoCloseable) {
34 try {
35 ((AutoCloseable) obj).close();
36 } catch (Exception ignored) {
37
38 }
39 }
40 }
41 }
42 }