From b594bb23fed13f74d622d5db7e7b57da7d237895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 7 May 2021 23:18:26 +0200 Subject: [PATCH] Checkstyle + pmd --- .../lang/rule/internal/RuleApplicator.java | 31 ++++++++++--------- .../lang/java/types/ast/PolyResolution.java | 3 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java index bbcb7a1b51..d2683c177a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java @@ -63,25 +63,28 @@ public class RuleApplicator { rule.apply(node, ctx); rcto.close(1); } catch (RuntimeException e) { - if (ctx.isIgnoreExceptions()) { - reportException(ctx, rule, node, e); - } else { - throw AssertionUtil.addContextValue(e, "Rule applied on node", node); - } - } catch (StackOverflowError | AssertionError e) { - if (SystemProps.isErrorRecoveryMode()) { - reportException(ctx, rule, node, e); - } else { - if (e instanceof AssertionError) { - throw AssertionUtil.addContextValue((AssertionError) e, "Rule applied on node", node); - } - throw e; - } + reportOrRethrow(ctx, rule, node, e, ctx.isIgnoreExceptions()); + } catch (AssertionError | StackOverflowError e) { + reportOrRethrow(ctx, rule, node, e, SystemProps.isErrorRecoveryMode()); } } } } + private void reportOrRethrow(RuleContext ctx, Rule rule, Node node, E e, boolean reportAndDontThrow) throws E { + if (reportAndDontThrow) { + reportException(ctx, rule, node, e); + } else { + if (e instanceof RuntimeException) { + throw AssertionUtil.addContextValue((RuntimeException) e, "Rule applied on node", node); + } else if (e instanceof AssertionError) { + throw AssertionUtil.addContextValue((AssertionError) e, "Rule applied on node", node); + } else { + throw e; + } + } + } + private void reportException(RuleContext ctx, Rule rule, Node node, Throwable e) { ctx.getReport().addError(new ProcessingError(e, String.valueOf(ctx.getSourceCodeFile()))); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java index 0d6ddcec0f..10bc683b79 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java @@ -550,8 +550,7 @@ final class PolyResolution { case OR: case XOR: case AND: - return ctxType == ts.BOOLEAN ? booleanCtx - : newNumericContext(ctxType); // NOPMD CompareObjectsWithEquals + return ctxType == ts.BOOLEAN ? booleanCtx : newNumericContext(ctxType); // NOPMD CompareObjectsWithEquals case LEFT_SHIFT: case RIGHT_SHIFT: case UNSIGNED_RIGHT_SHIFT: