Description
SonarQube:
Declaring a variable only to immediately return or throw it is a bad practice.
Some developers argue that the practice improves code readability, because it enables them to explicitly name what is being returned. However, this variable is an internal implementation detail that is not exposed to the callers of the method. The method name should be sufficient for callers to know exactly what will be returned.
Problem:
Create a variable only to return it from a method in the next step.
Solution:
Returning the result of a method, without unnecessary assigning to a variable.
Where the problem occurs:
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java#L528-L529
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java#L414-L415
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java#L233-L234
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java#L157-L161
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java#L166-L168
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java#L103-L104
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingConverter.java#L67-L68
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java#L414-L416
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java#L839-L840
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java#L906-L907
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/ConversionUtil.java#L243-L244
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingCrudResource.java#L180-L181
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/api/impl/RestServiceImpl.java#L479-L481
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestUtil.java#L504-L505
- https://github.com/openmrs/openmrs-module-webservices.rest/blob/2.28.0/omod-common/src/main/java/org/openmrs/module/webservices/rest/SimpleObject.java#L71-L72
Support materials:
- explanation of the problem by SonarQube: https://sonar.openmrs.org/coding_rules#rule_key=squid%3AS1488