This change fixes "Local variables should not be declared and then immediately returned or thrown" (id = java:S1488) identified by Sonar.
Details
This change removes intermediate variables who are only created to be thrown or returned in the next statement. This makes the code more readable, which makes reviewing the code for issues easier.
Our changes look something like this:
public LocaleResolver localeResolver() {
- SessionLocaleResolver localeResolver = new SessionLocaleResolver();
- return localeResolver;
+ return new SessionLocaleResolver();
}
public void process() {
- Exception ex = new Exception();
- throw ex;
+ throw new Exception();
}
More reading
* [https://rules.sonarsource.com/java/RSPEC-1488/](https://rules.sonarsource.com/java/RSPEC-1488/)
I have additional improvements ready for this repo! If you want to see them, leave the comment:
Remediation
This change fixes "Local variables should not be declared and then immediately returned or thrown" (id = java:S1488) identified by Sonar.
Details
This change removes intermediate variables who are only created to be thrown or returned in the next statement. This makes the code more readable, which makes reviewing the code for issues easier.
Our changes look something like this:
More reading
* [https://rules.sonarsource.com/java/RSPEC-1488/](https://rules.sonarsource.com/java/RSPEC-1488/)I have additional improvements ready for this repo! If you want to see them, leave the comment:
... and I will open a new PR right away!
🧚🤖 Powered by Pixeebot
Feedback | Community | Docs | Codemod ID: sonar:java/remove-redundant-variable-creation-s1488