Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Potential unreachable condition in FileInfo.moveToNewLocation #4736

Copy link
Copy link

Description

@silviaperelli
Issue body actions

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:

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:

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:

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.