Changing version bug

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

Bug Description

Hi,

I found another error in databasehelper.java.
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):

databasehelper.java
...
// Chunks from previous version
        if (update.getVersion() > 1) {
            CloneFile previousVersion = getFileOrFolder(profile, update.getFileId(), update.getVersion() - 1);

            if (previousVersion != null) {
                newFile.setChunks(previousVersion.getChunks());
            }
            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.

clonefile.java
...
    public void setChunks(List<CloneChunk> chunks) {
        this.chunks = chunks;
    }

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

databasehelper.java
...
        // Chunks changed
        if (!update.getChunksChanged().isEmpty()) {
            for (Map.Entry<Integer, Long> entry : update.getChunksChanged().entrySet()) {
                int chunkIndex = entry.getKey();
                long chunkId = entry.getValue();

                em.getTransaction().begin();

                CloneChunk chunk = getChunk(chunkId, true);

                em.merge(chunk);
                em.flush();
                em.getTransaction().commit();

                newFile.setChunk(chunkIndex, chunk);
            }
        }

To solve this I do some changes in the file clonefile.java:

clonefile.java
...
    public void setChunks(List<CloneChunk> chunks) {
        this.chunks = new ArrayList<CloneChunk>(chunks);
    }

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

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

Regards!

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

Other bug subscribers