ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 37501] New: - IntrospectionHelper is not thread-safe
Date Mon, 14 Nov 2005 19:20:22 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=37501>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=37501

           Summary: IntrospectionHelper is not thread-safe
           Product: Ant
           Version: 1.6.5
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core
        AssignedTo: dev@ant.apache.org
        ReportedBy: dennis.homann@coremedia.com


We use Ant programmatically to build many projects in parallel. The more load 
we have on this build system, the more often we encounter spurious 
exceptions such as the following. Retrying the build will most often heal the 
situation:

The <property> type doesn't support the "location" attribute.
        at org.apache.tools.ant.IntrospectionHelper.setAttribute
(IntrospectionHelper.java:389)
        at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure
(RuntimeConfigurable.java:370)
        at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure
(RuntimeConfigurable.java:324)
        at org.apache.tools.ant.Task.maybeConfigure(Task.java:254)
        at org.apache.tools.ant.UnknownElement.configure
(UnknownElement.java:189)
        at org.apache.tools.ant.UnknownElement.maybeConfigure
(UnknownElement.java:158)
        at org.apache.tools.ant.Task.perform(Task.java:363)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1185)

We tracked this down to 
org.apache.tools.ant.IntrospectionHelper#buildFinished, which 1. clears 
several member hash maps and 2. clears the static helper cache without 
synchronization:

    public void buildFinished(BuildEvent event) {
        attributeTypes.clear();
        attributeSetters.clear();
        nestedTypes.clear();
        nestedCreators.clear();
        addText = null;
        helpers.clear();
    }

With respect to point 1, I do not believe clearing those maps is necessary. It 
is also a potential cause of concurrency issues. If thread 1 retrieved this 
helper instance from getHelper(Class) while thread 2 executes #buildFinished, 
exceptions like the one above will be thrown. In that case we do not really 
want to clear the maps anyway, because the information is still in use. If, on 
the other hand, no other thread holds a reference to this IntrospectionHelper, 
the GC will free all associated memory as soon as the "helpers" cache is 
cleared. So clearing the maps does not gain anything.

With respect to point 2, please consider clearing the "helpers" cache in a 
synchronized fashion, if at all. The helpers cache will contain at most (!) 
one mapping per loaded class and will therefore not grow indefinitely. 
Clearing the cache is not necessary from my point of view.

In a separate discussion it was mentioned that Ant is not designed to be 
thread-safe. One difficulty is that there are too many task implementations 
out there to guarantee thread-safety in general. However, the core should be 
made thread-safe and it should be documented that some tasks might not work 
well in multi-threaded environments. The goal is not to build the same project 
instance concurrently, but at least to be able to build different project 
instances concurrently (which is not possible right now due to the map 
synchronization bug described above).

That said, my suggestion is either to do nothing in #buildFinished, or to 
replace it with 

    private static synchronized void clearHelperCache() {
        helpers.clear();
    }
    public void buildFinished(BuildEvent event) {
        clearHelperCache();
    }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message