'SonarQube major isuue raised 'Define and throw a dedicated exception instead of using a generic one.'?

I need to throw RuntimeException for the KeycloakAuthenticationProvider . We are using SonarQube tool for code review purpose.

Here is the code

public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
      KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
      auth.authenticationProvider(keycloakAuthenticationProvider);
 }

Now, SonarQube raises an issue for the same , Now what should be replaced to fix the sonar violation.



Solution 1:[1]

The issue here is the throws Exception in your method signature:

public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception 

SonarQube informs you that instead of the generic Exception that is the basis of all exceptions, both checked and unchecked you shoud reference the actual (checked) exception that may be thrown by the methods that you are calling.

Usually, your IDE should already suggest a suitable Exception class.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 void