You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2022/11/14 15:34:33 UTC

[GitHub] [fineract] b0c1 opened a new pull request, #2744: FINERACT-1724 - Fix possible null values

b0c1 opened a new pull request, #2744:
URL: https://github.com/apache/fineract/pull/2744

   ## Description
   
   Describe the changes made and why they were made.
   
   Small modifications to resolve some sonar issues. Covered by existing unit and integration tests.
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [x] Write the commit message as per https://github.com/apache/fineract/#pull-requests
   
   - [x] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   
   - [x] Create/update unit or integration tests for verifying the changes made.
   
   - [x] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
   
   - [x] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   
   - [x] Submission is not a "code dump".  (Large changes can be made "in repository" via a branch.  Ask on the developer mailing list for guidance, if required.)
   
   FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] b0c1 commented on a diff in pull request #2744: FINERACT-1724 - Fix possible null values

Posted by GitBox <gi...@apache.org>.
b0c1 commented on code in PR #2744:
URL: https://github.com/apache/fineract/pull/2744#discussion_r1022109497


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/filter/LoanCOBApiFilter.java:
##########
@@ -133,17 +133,9 @@ private void reject(Long loanId, HttpServletResponse response, int status) throw
 
     private Long getLoanId(boolean isGlim, Supplier<Stream<String>> streamSupplier) {
         if (!isGlim) {
-            if (streamSupplier.get().count() >= LOAN_ID_INDEX_IN_URL + 1) {
-                return Long.valueOf(streamSupplier.get().skip(LOAN_ID_INDEX_IN_URL).findFirst().get());
-            } else {
-                return null;
-            }
+            return streamSupplier.get().skip(LOAN_ID_INDEX_IN_URL).findFirst().map(Long::valueOf).orElse(null);

Review Comment:
   I checked the original test suite, and I think we can't write the test to the else branch because the `isOnApiList` will ignore the request if it's not match the pattern `/loans/\d+.*` or `/loans/glimAccount/\d+.*`. 
   The modification does two things:
    - remove the unnecessary count check, because if the skip is greater than the stream, it will return an empty stream.
    - Sonar marked the code with major issue because the `findFirst` will return with Optional, but not checked the result before you access with `get`.
    So it's not modify the current behavior, just reduce the code and eliminating the Sonar issues.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] galovics commented on a diff in pull request #2744: FINERACT-1724 - Fix possible null values

Posted by GitBox <gi...@apache.org>.
galovics commented on code in PR #2744:
URL: https://github.com/apache/fineract/pull/2744#discussion_r1021800789


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/filter/LoanCOBApiFilter.java:
##########
@@ -133,17 +133,9 @@ private void reject(Long loanId, HttpServletResponse response, int status) throw
 
     private Long getLoanId(boolean isGlim, Supplier<Stream<String>> streamSupplier) {
         if (!isGlim) {
-            if (streamSupplier.get().count() >= LOAN_ID_INDEX_IN_URL + 1) {
-                return Long.valueOf(streamSupplier.get().skip(LOAN_ID_INDEX_IN_URL).findFirst().get());
-            } else {
-                return null;
-            }
+            return streamSupplier.get().skip(LOAN_ID_INDEX_IN_URL).findFirst().map(Long::valueOf).orElse(null);

Review Comment:
   As far as I can tell the original test suite for this class doesn't cover the else branch so please add new tests for it.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/filter/LoanCOBApiFilter.java:
##########
@@ -155,9 +147,6 @@ private boolean isOnApiList(HttpServletRequest request) {
     }
 
     private boolean isGlim(Supplier<Stream<String>> streamSupplier) {
-        if (streamSupplier.get().count() >= GLIM_STRING_INDEX_IN_URL + 1) {
-            return "glimAccount".equals(streamSupplier.get().skip(GLIM_STRING_INDEX_IN_URL).findFirst().get());
-        }
-        return false;
+        return streamSupplier.get().skip(GLIM_STRING_INDEX_IN_URL).findFirst().map(s -> s.equals("glimAccount")).orElse(false);

Review Comment:
   Same as above.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/filter/LoanCOBApiFilter.java:
##########
@@ -133,17 +133,9 @@ private void reject(Long loanId, HttpServletResponse response, int status) throw
 
     private Long getLoanId(boolean isGlim, Supplier<Stream<String>> streamSupplier) {
         if (!isGlim) {
-            if (streamSupplier.get().count() >= LOAN_ID_INDEX_IN_URL + 1) {
-                return Long.valueOf(streamSupplier.get().skip(LOAN_ID_INDEX_IN_URL).findFirst().get());
-            } else {
-                return null;
-            }
+            return streamSupplier.get().skip(LOAN_ID_INDEX_IN_URL).findFirst().map(Long::valueOf).orElse(null);
         } else {
-            if (streamSupplier.get().count() >= GLIM_ID_INDEX_IN_URL + 1) {
-                return Long.valueOf(streamSupplier.get().skip(GLIM_ID_INDEX_IN_URL).findFirst().get());
-            } else {
-                return null;
-            }
+            return streamSupplier.get().skip(GLIM_ID_INDEX_IN_URL).findFirst().map(Long::valueOf).orElse(null);

Review Comment:
   Same as above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [fineract] galovics merged pull request #2744: FINERACT-1724 - Fix possible null values

Posted by GitBox <gi...@apache.org>.
galovics merged PR #2744:
URL: https://github.com/apache/fineract/pull/2744


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org