Bug 565874 - DfsPackFile readFully EOFException when creating a repository twice in same process
Summary: DfsPackFile readFully EOFException when creating a repository twice in same p...
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.8   Edit
Hardware: Other Android
: P3 normal (vote)
Target Milestone: 5.11   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-07 03:19 EDT by Guest Account CLA
Modified: 2021-02-19 18:37 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guest Account CLA 2020-08-07 03:19:36 EDT
In my program, I do a few actions on a repository object and dispose of it. I'd create a new repository object to do more later. This results in multiple DfsPackFile objects that represent the same file in the same repository existing throughout the process's life.

In the DfsReader `copy` method, it loops through blocks in the file, on a condition `while (0 < need && position < length)`, with `length` taken from `file.length`, and where `file.length` is intended to be initialized when the `pin` call inside the loop loads the first block needed.

However, when doing this for the second time on a fresh repository object DfsPackFile, sometimes the DfsBlockCache, which is a single shared instance, will contain the blocks needed. This results in no access to the file, which results in `file.length` not being populated--it remains -1. This causes the loop in `copy` to exit due to `position < length` not being satisfied, which causes `copy` to return without copying as many bytes as requested.

For one thing, although "read" methods sometimes have this inconvenient behavior of sometimes reading fewer bytes than requested, such behavior is not documented in in `copy`.

And more importantly, the `readFully` method of DfsPackFile only calls `copy` once, and throws EOFException if it comes up short.
Comment 1 Eclipse Genie CLA 2020-12-17 17:38:27 EST
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/173947