spring-security-registration icon indicating copy to clipboard operation
spring-security-registration copied to clipboard

Fix non-public methods should not be @Transactional

Open sara4cristina opened this issue 3 years ago • 0 comments

Hi!

I've recently checked your project with SonarQube as a university task. For extra credits I need to do a pull request that will get merged. I put down below all the details about the bug I found.

Hope it hepls!

image

I found this bug in src/main/java/com/baeldung/spring/SetupDataLoader.java on three diferent methods:

  • createPrivilegeIfNotFound
  • createRoleIfNotFound
  • createUserIfNotFound

Why is this an isssue?

Non-public methods should not be "@Transactional"

Marking a non-public method @Transactional is both useless and misleading because Spring doesn’t "see" non-public methods, and so makes no provision for their proper invocation. Nor does Spring make provision for the methods invoked by the method it called.

Therefore marking a private method, for instance, @Transactional can only result in a runtime error or exception if the method is actually written to be @Transactional.

Have a great one!

sara4cristina avatar Jun 13 '22 17:06 sara4cristina