|
14 | 14 | /** Removes exposure from error messages. */ |
15 | 15 | public final class ErrorMessageExposureFixStrategy extends MatchAndFixStrategy { |
16 | 16 |
|
17 | | - private static List<String> printErrorMethods = List.of("printStackTrace"); |
18 | | - private static List<String> printMethods = List.of("println", "print", "sendError"); |
| 17 | + private static final List<String> printErrorMethods = List.of("printStackTrace"); |
| 18 | + private static final List<String> printMethods = List.of("println", "print", "sendError"); |
19 | 19 |
|
20 | 20 | /** |
21 | 21 | * Test if the node is an expression that is the argument of a method call |
@@ -45,27 +45,25 @@ public boolean match(final Node node) { |
45 | 45 |
|
46 | 46 | @Override |
47 | 47 | public SuccessOrReason fix(final CompilationUnit cu, final Node node) { |
48 | | - // we know from the match that this is true |
49 | | - Expression expr = (Expression) node; |
50 | 48 | // find encompassing statement |
51 | 49 | Optional<Statement> maybeStmt = |
52 | 50 | Optional.<MethodCallExpr>empty() |
53 | 51 | // grab the relevant method call from the two cases |
54 | 52 | .or( |
55 | 53 | () -> |
56 | 54 | Optional.of(node) |
57 | | - .map(n -> n instanceof Expression ? (Expression) n : null) |
| 55 | + .map(n -> n instanceof Expression e ? e : null) |
58 | 56 | .flatMap(ASTs::isArgumentOfMethodCall) |
59 | 57 | .filter(mce -> printMethods.contains(mce.getNameAsString()))) |
60 | 58 | // is itself a method call that send errors: e.g. err.printStackTrace() |
61 | 59 | .or( |
62 | 60 | () -> |
63 | 61 | Optional.of(node) |
64 | | - .map(n -> n instanceof Expression ? (Expression) n : null) |
65 | | - .flatMap(e -> e.toMethodCallExpr()) |
| 62 | + .map(n -> n instanceof Expression e ? e : null) |
| 63 | + .flatMap(Expression::toMethodCallExpr) |
66 | 64 | .filter(mce -> printErrorMethods.contains(mce.getNameAsString()))) |
67 | 65 | // check if the method call is in a statement by itself |
68 | | - .flatMap(mce -> mce.getParentNode()) |
| 66 | + .flatMap(Node::getParentNode) |
69 | 67 | .map(p -> p instanceof ExpressionStmt ? (ExpressionStmt) p : null); |
70 | 68 | // Remove it |
71 | 69 | if (maybeStmt.isPresent()) { |
|
0 commit comments