From 666a617be109bf95ae1903af04b89a8d4852fd6a Mon Sep 17 00:00:00 2001 From: Scott Leberknight <174812+sleberknight@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:44:10 -0500 Subject: [PATCH] Sonar cleanup in AbstractInvoker (#33) * Make constructor of AbstractInvoker protected (java:S5993 - Constructors of an "abstract" class should not be declared "public") * Remove unnecessary null check in AbstractInvoker (java:S4201 - Null checks should not be used with "instanceof") * Remove null check and use pattern matching in AbstractInvoker (java:S4201 - Null checks should not be used with "instanceof"; java:S6201 - Pattern Matching for "instanceof" operator should be used instead of simple "instanceof" + cast) * Remove redundant abstract method in AbstractInvoker (java:S3038 Abstract methods should not be redundant) * Throw dedicated exception in AbstractInvoker. Throw an IllegalStateException instead of RuntimeException when the target method can't be found (java:S112 - Generic exceptions should never be thrown) --- .../dropwizard/jaxws/AbstractInvoker.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java index f4c0bab..a880602 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java @@ -12,7 +12,7 @@ public abstract class AbstractInvoker implements Invoker { protected Invoker underlying; - public AbstractInvoker(Invoker underlying) { + protected AbstractInvoker(Invoker underlying) { this.underlying = underlying; } @@ -23,22 +23,18 @@ public Method getTargetMethod(Exchange exchange) { Object o = exchange.getBindingOperationInfo().getOperationInfo().getProperty(Method.class.getName()); - if (o != null && o instanceof Method) { - return (Method)o; - } - else { - throw new RuntimeException("Target method not found on OperationInfo"); + if (o instanceof Method method) { + return method; + } else { + throw new IllegalStateException("Target method not found on OperationInfo"); } } - @Override - public abstract Object invoke(Exchange exchange, Object o); - /** - * Rethrows exception, without requiring to handle checked exception. - * Type-erasure happens at compile time, therefore if E is RuntimeException, - * checked exception can be re-thrown without declaring them. + * Rethrows exception, without requiring to handle checked exception. + * Type-erasure happens at compile time, therefore if E is RuntimeException, + * checked exception can be re-thrown without declaring them. */ @SuppressWarnings("unchecked") protected void rethrow(Exception e) throws E {