ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey E Care <ca...@us.ibm.com>
Subject Possible bug in ResourceUtils and/or FileResource?
Date Thu, 09 Feb 2012 22:19:02 GMT
I was trying to track down some strange behavior in one of our custom 
resource collections and I think that I might have stumbled across a 
potential but in ResourceUtils. Specifically, in the "asFileResource" 
method:

    /**
     * Convenience method to turn any fileProvider into a basic
     * FileResource with the file's immediate parent as the basedir,
     * for tasks that need one.
     * @param fileProvider input
     * @return fileProvider if it is a FileResource instance, or a new
     * FileResource with fileProvider's file.
     * @since Ant 1.8
     */
    public static FileResource asFileResource(FileProvider fileProvider) {
        if (fileProvider instanceof FileResource || fileProvider == null) 
{
            return (FileResource) fileProvider;
        }
        FileResource result = new FileResource(fileProvider.getFile());
        result.setProject(Project.getProject(fileProvider));
        return result;
    }

This method purports to return a FileResource whose baseDir will be the 
parent of the file returned by the passed FileProvider. The only problem 
is that setBaseDir is never called on the new'ed up FileResource from this 
code path. Also, in the instanceof case there's no promise that the 
FileProvider cast to FileResource has a non-null basedir either.

The fix for my collection was simply to set the basedir on all of its 
resources. I think the real fix here might be that the FileResource(File) 
constructor should also set the basedir on the FileResource to the passed 
File's parent? I'm not sure the best way to fix this but I think that 
something is clearly not right.

____________________________________________________________________________________________


Jeffrey E. (Jeff) Care 
carej@us.ibm.com 
IBM WebSphere Application Server 
WAS Release Engineering 




Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message