Changing version bug

Bug #993815 reported by Guillermo Guerrero on 2012-05-03
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description


I found another error in
The error is produced by the wrong use of referencial and copy value objects.

In funtion public CloneFile createFile(Profile profile, Update update, SyncStatus syncStatus):
// Chunks from previous version
        if (update.getVersion() > 1) {
            CloneFile previousVersion = getFileOrFolder(profile, update.getFileId(), update.getVersion() - 1);

            if (previousVersion != null) {
            else {
                if (logger.isLoggable(Level.WARNING)) {
                    logger.log(Level.WARNING, "Could not find previous version for file {0} in database.", newFile);

when do the newFile.setChunks this copy the reference of chunk's list and after when remplace the chunks replace the chunks of current version and before version.
    public void setChunks(List<CloneChunk> chunks) {
        this.chunks = chunks;

    public void setChunk(int index, CloneChunk chunk) {
        chunks.set(index, chunk);
        // Chunks changed
        if (!update.getChunksChanged().isEmpty()) {
            for (Map.Entry<Integer, Long> entry : update.getChunksChanged().entrySet()) {
                int chunkIndex = entry.getKey();
                long chunkId = entry.getValue();


                CloneChunk chunk = getChunk(chunkId, true);


                newFile.setChunk(chunkIndex, chunk);

To solve this I do some changes in the file
    public void setChunks(List<CloneChunk> chunks) {
        this.chunks = new ArrayList<CloneChunk>(chunks);

    public void setChunk(int index, CloneChunk chunk) {
        chunks.add(index, chunk);

And now the chunks list of any version are copy and not reference.


To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers