silviaperelli opened a new issue, #4736:
URL: https://github.com/apache/bookkeeper/issues/4736

   **BUG REPORT**
   
   ***Describe the bug***
   
   While analyzing the implementation of FileInfo.moveToNewLocation, I noticed 
a condition that appears to be unreachable.
   
   Specifically, the following check:
   
   ```java
   if (written <= 0 && size > 0)
   ```
   
   seems redundant given the logic of the preceding loop.
   
   ***To Reproduce***
   
   This is not a runtime bug but a logical issue identified through static 
analysis.
   
   Relevant code:
   
   ```java
   long written = 0;
   while (written < size) {
       long count = fc.transferTo(written, size, newFc);
       if (count <= 0) {
           throw new IOException("Copying to new location " + rlocFile + " 
failed");
       }
       written += count;
   }
   ```
   
   ***Expected behavior***
   
   The condition after the loop should represent a reachable state.
   
   However, based on the current logic:
   
   - If size > 0, the loop executes at least once.
   - If count <= 0, an exception is thrown immediately.
   - Otherwise, written is incremented (written += count, with count > 0).
   
   Therefore, after normal loop termination, written should always be greater 
than 0.
   
   ***Screenshots***
   
   Not applicable.
   
   ***Additional context***
   
   Given the loop semantics, the condition:
   
   ```java
   if (written <= 0 && size > 0)
   ```
   
   appears to be unreachable.
   
   This might be:
   
   - a leftover defensive check, or
   - redundant code that could be removed for clarity.
   
   cc @gulyx
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to