ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steele, Richard" <>
Subject ProjectHelper2 fails to close input source after parsing imported document?
Date Tue, 25 Oct 2011 15:35:07 GMT
I'm chasing a defect with one of my custom Ant tasks.  To summarize, the
task uses ImportTask under the hood to import build scripts.  These scripts
can come from jar files downloaded via Ivy.  The problem I'm running into is
that, at least on Windows, I'm unable to clean the project because Ant has a
file handle open to the jar file I'm importing from.

I think what might be happening, and this is just a guess, is that the SAX
parser is opening the jar file but not closing it.  The code where I'm
seeing the problem is in ProjectHelper2, starting at line 307:


This is wrapped in a finally block, at line 335:

finally {

I've debugged to the point where, before calling the parse() method there's
only one file handle open to the jar.  (I'm using Process Explorer to watch
the file handles opening and closing.)  However, after the parse method, and
before calling the FileUtils.close() in the finally block, I see two handles
open.  The FileUtils.close() method then closes one of them, but there's
still a file handle left open after the import file has been parsed.

I'm fuzzy on whether or not an implementor of
org.xml.sax.XMLReader.parse(InputSource) should close the input source, or
if that's the responsibility of the caller.  It appears the caller should,
and it looks like the Ant parser is in fact doing that by closing the
inputStream (which forms the InputSource).  However, digging a bit deeper
into the bowels of the built-in SAX parser I see code in XMLVersionDetector,
line 186:

fEncoding = fEntityManager.setupCurrentEntity(fXMLSymbol, inputSource,
false, true);

It's this line which opens the second file handle.  In fact, looking through
the source for XMLEntityManager I see an input stream opened but never
closed.  Could this be the source of my problems?

Clearly this would not be an Ant problem, but I'm wonder if this is
something anyone else has happened across?  I can't believe there would be a
file handle leak deep inside the SAX parser.  If there is a defect like
this, short of reporting it, is there anything I can do with Ant to sidestep
the issue?

I'm running Windows XP with Ant 1.8.2 and Java 6 (build build 1.6.0_22-b04).


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