Skip to main content
added 55 characters in body
Source Link
janos
  • 113.1k
  • 15
  • 154
  • 396

It's good to make fields final when possible, for example:

private final Service instance;

and also in the InboundHandling class:

private final Pattern p = ...

Avoid declaring methods with throws Exception and catching exceptions with catch (Exception s). Throw the most specific kind of exception possible, and do likewise when catching. For one thing, it tells readers of the code a lot about what can go wrong inside the method, or block of code, which is very useful. But even more importantly, it avoids masking exceptions that are actually unexpected and could be the result of bugs or oversight.


The nested InboundHandling class should be static, as it doesn't need anything from the enclosing class. This improves performance, and clarity of the design.

It's good to make fields final when possible, for example:

private final Service instance;

and also in the InboundHandling class:

private final Pattern p = ...

Avoid declaring methods with throws Exception and catching exceptions with catch (Exception s). Throw the most specific kind of exception possible, and do likewise when catching. For one thing, it tells readers of the code a lot about what can go wrong inside the method, or block of code, which is very useful. But even more importantly, it avoids masking exceptions that are actually unexpected and could be the result of bugs or oversight.


The nested InboundHandling class should be static, as it doesn't need anything from the enclosing class.

It's good to make fields final when possible, for example:

private final Service instance;

and also in the InboundHandling class:

private final Pattern p = ...

Avoid declaring methods with throws Exception and catching exceptions with catch (Exception s). Throw the most specific kind of exception possible, and do likewise when catching. For one thing, it tells readers of the code a lot about what can go wrong inside the method, or block of code, which is very useful. But even more importantly, it avoids masking exceptions that are actually unexpected and could be the result of bugs or oversight.


The nested InboundHandling class should be static, as it doesn't need anything from the enclosing class. This improves performance, and clarity of the design.

Source Link
janos
  • 113.1k
  • 15
  • 154
  • 396

It's good to make fields final when possible, for example:

private final Service instance;

and also in the InboundHandling class:

private final Pattern p = ...

Avoid declaring methods with throws Exception and catching exceptions with catch (Exception s). Throw the most specific kind of exception possible, and do likewise when catching. For one thing, it tells readers of the code a lot about what can go wrong inside the method, or block of code, which is very useful. But even more importantly, it avoids masking exceptions that are actually unexpected and could be the result of bugs or oversight.


The nested InboundHandling class should be static, as it doesn't need anything from the enclosing class.