Detect useless transaction annotations on methods in EJB's

A basic rule could be like RSPEC-2230: detection @TransactionAttribute annotation on non-public methods.

Non-compliant code:

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
void doTheThing(ArgClass arg) {
  // ...
}

This could be extended to checking whether public methods with a @TransactionAttribute annotation are called from within the bean. According to the spec and real-life tests, this has no effect.

Non-compliant code:

// attribute on public method is compliant
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void doTheThingAndMoreOfIt(ArgClass arg) {
  doTheThing(ArgClass arg); // ...but this call is non-compliant, or at least a code smell
  // ...
}

// attribute on public method is compliant
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void doTheThing(ArgClass arg) {
  // ...
}

Some background:

Hi RonaldT,

Thank you your your suggestion which I agree with.
I created 2 tickets.

Regards,
Richard

Great, thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.