[
https://issues.apache.org/jira/browse/GROOVY-7401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149107#comment-18149107
]
Daniel Sun commented on GROOVY-7401:
------------------------------------
Fixed on master; added a regression test in
e14d1261b08507f9c79d79cd2e2aa18228b43518
(https://github.com/apache/groovy/commit/e14d1261b08507f9c79d79cd2e2aa18228b43518).
> groovy will not reload scripts if the script is located in a symlink
> --------------------------------------------------------------------
>
> Key: GROOVY-7401
> URL: https://issues.apache.org/jira/browse/GROOVY-7401
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.3.7
> Reporter: Luke Butters
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 7.0.0-alpha-1
>
>
> The issue is when you tell groovy too look in a path, where part of the path
> is sym-link. for example /foo points to /bar
> {code}
> GroovyClassLoader groovyClassLoader = new GroovyClassLoader(parent);
> groovyClassLoader.addClasspath(/foo/groovy/);
> {code}
> if we then get a class from groovy with a
> {code}
> Class<?> c =
> groovyClassLoaderCache.getCollectionGroovyClassLoader(collectionName).loadClass("package.CoolClass",
> true, false);
> {code}
> we then edit CoolClass
> then make the above call we will get the same class.
> This happens because inside GroovyClassLoader#recompile(URL source, String
> className, Class oldClass);
> we have the following:
> {code}
> // we remove from the source cache the class we will reload.
> //note that here we remove something in the sym linked path ie /foo/...
> String name = source.toExternalForm();
> sourceCache.remove(name);
> ...
> //source toUri is still in the symlink path
> return parseClass(new GroovyCodeSource(new File(source.toURI()),
> config.getSourceEncoding()));
> {code}
> Now inside parseClass we have:
> {code}
> //Here we actually get a non null answer because the entry we removed earlier
> was not the same as the one here
> //Note that codeSource.getName() is resolved, ie in /bar/
> Class answer = sourceCache.get(codeSource.getName());
> //this returns with the old class we tried but failed to remove from the
> cache earlier
> if (answer != null) return answer;
> {code}
> So the issue is, we generate a different key for the same path which results
> in us not removing the correct cached class resulting in the cache class
> always being returned.
> Looking at the latest source of groovy the latest version is probably
> affected.
> A workaround exists where the the class path added should be canonicalised, i
> guess a lazy solution is to change the java doc of addClasspath to be "the
> canonical path to jar or directory"
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)