History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2811
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Hans Lund
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

GroovyClassLoader.isSourceNewer() fails when url has spaces

Created: 06/May/08 04:22 PM   Updated: 09/May/08 03:18 AM
Component/s: None
Affects Version/s: 1.6-beta-1
Fix Version/s: 1.5.7, 1.6-beta-2

Time Tracking:
Not Specified

File Attachments: 1. Java Source File GroovyClassLoaderTest.java (6 kb)

Environment:
Java Runtime Environment version: 1.6.0_04
Java Runtime Environment vendor: Sun Microsystems Inc.
Ant version: Apache Ant version 1.7.0 compiled on December 13 2006
Operating system name: Windows XP
Operating system architecture: x86
[echo] Operating system version: 5.1
[echo] Base directory: C:\arbejde\workspace2\groovy

Testcase included: yes


 Description  « Hide
The GroovyClassLoader fails to recompile scripts when the script path contains spaces, as the file latest modified always return 0 (file not found).
I think this is related to Groovy-1787 issue.

As a consequence scripts cashed by a GroovyClassLoader will not be updated even if the source is replaced.

I've extended the GroovyClassLoaderTest.java with a new test method that demonstrate the issue. My guess is that this is not the proper location so someone with a better understanding that me of the project structure should properly move/refactor it.

Also as far as I can see a fix is almost trivial? within the isSorceNewer() method the filepath:

String path = source.getPath().replace('/', File.separatorChar).replace('|', ':');

should be parsed through the internal decodeFileName prior to creating the file object.

But I'm not convinced that this is the proper fix?



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jochen Theodorou - 08/May/08 01:14 PM
a space is encoded as %20, thus when in isSourceNewer a file object is created it looks for "%20" instead of " ". The result is that it won't work. URLDecode.decode(url.getPath(),"UTF8") should be used instead. It should also be tested if source.getPath().replace('/', File.separatorChar).replace('|', ':'); is still needed after a call to decode.

Hans Lund - 09/May/08 03:18 AM
Having had a closer look, there seams to be a general approach regarding URL -> File conversion.

method(URL url){ String path = url.getPath(); // some code to compensate for the errors now introduced path = ........ File f = new File(path); .....}

where I think in most cases URL and URI classes handles this well (makes system depended, conversions)
can be replaced with:
method(URL url)
if (isFile...){ File file = new File(url.toURI()); .....}

at least I think this should hold for isSourceNewer()
can be refactored and fixed with->

protected boolean isSourceNewer(URL source, Class cls) throws IOException {
long lastMod;

// Special handling for file:// protocol, as getLastModified() often reports
// incorrect results (-1)
if (source.getProtocol().equals("file")) { File file = new File(source.toURI()); lastMod = file.lastModified(); } else { URLConnection conn = source.openConnection(); lastMod = conn.getLastModified(); conn.getInputStream().close(); }
long classTime = getTimeStamp(cls);
return classTime + config.getMinimumRecompilationInterval() < lastMod;
}