[ 
https://issues.apache.org/jira/browse/VFS-220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gilles Gaillard updated VFS-220:
--------------------------------

    Description: 
Method endOutput() is called when a file is created or an outputstream closed.
The current code says: 
{noformat} 
    if (getType() == FileType.IMAGINARY) {
        // File was created
        handleCreate(FileType.FILE);
    } else {
        // File has changed
        onChange();
    }
{noformat}
Calling getType() on a file that wasn't previously attached will cause the file 
to be attached and therefore 
not return FileType.IMAGINARY since it's just been created. Hence the list of 
children in the parent will 
become wrong.

To correct, replace the test by 'if (type == FileType.IMAGINARY)', and the 
method becomes:
{noformat}
    protected void endOutput() throws Exception
    {
        // NOTE: don't use getType() here
        if (type == FileType.IMAGINARY)
        {
            // File was created
            handleCreate(FileType.FILE);
        }
        else
        {
            // File has changed
            onChange();
        }
    }
{noformat}

  was:
Method endOutput() is called when a file is created or an outputstream closed.
The current code says:
    if (getType() == FileType.IMAGINARY) {
        // File was created
        handleCreate(FileType.FILE);
    } else {
        // File has changed
        onChange();
    }
Calling getType() on a file that wasn't previously attached will cause the file 
to be attached and therefore 
not return FileType.IMAGINARY since it's just been created. Hence the list of 
children in the parent will 
become wrong.

To correct, replace the test by 'if (type == FileType.IMAGINARY)', and the 
method becomes:

    protected void endOutput() throws Exception
    {
        // NOTE: don't use getType() here
        if (type == FileType.IMAGINARY)
        {
            // File was created
            handleCreate(FileType.FILE);
        }
        else
        {
            // File has changed
            onChange();
        }
    }



suppress format for code excerpt

> Wrong test in AbstractFileObject.endOutput may cause invalid list of children
> -----------------------------------------------------------------------------
>
>                 Key: VFS-220
>                 URL: https://issues.apache.org/jira/browse/VFS-220
>             Project: Commons VFS
>          Issue Type: Bug
>         Environment: all
>            Reporter: Gilles Gaillard
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Method endOutput() is called when a file is created or an outputstream closed.
> The current code says: 
> {noformat} 
>     if (getType() == FileType.IMAGINARY) {
>         // File was created
>         handleCreate(FileType.FILE);
>     } else {
>         // File has changed
>         onChange();
>     }
> {noformat}
> Calling getType() on a file that wasn't previously attached will cause the 
> file to be attached and therefore 
> not return FileType.IMAGINARY since it's just been created. Hence the list of 
> children in the parent will 
> become wrong.
> To correct, replace the test by 'if (type == FileType.IMAGINARY)', and the 
> method becomes:
> {noformat}
>     protected void endOutput() throws Exception
>     {
>         // NOTE: don't use getType() here
>         if (type == FileType.IMAGINARY)
>         {
>             // File was created
>             handleCreate(FileType.FILE);
>         }
>         else
>         {
>             // File has changed
>             onChange();
>         }
>     }
> {noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to