Skip to content

Commit

Permalink
Sonar cleanup in AbstractInvoker (#33)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
sleberknight authored Nov 7, 2023
1 parent 2640d9e commit 666a617
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class AbstractInvoker implements Invoker {

protected Invoker underlying;

public AbstractInvoker(Invoker underlying) {
protected AbstractInvoker(Invoker underlying) {
this.underlying = underlying;
}

Expand All @@ -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 <E extends Exception> void rethrow(Exception e) throws E {
Expand Down

0 comments on commit 666a617

Please sign in to comment.