Skip to content

Commit 33f92e0

Browse files
committed
[MASSEMBLY-742] Fix take 42
1 parent d8b306a commit 33f92e0

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ else if ( o instanceof PlexusIoResourceCollection )
516516
}
517517
else
518518
{
519+
// this will leak handles in the IO iterator if the iterator is not fully consumed.
520+
// alternately we'd have to make this method return a Closeable iterator back
521+
// to the client and ditch the whole issue onto the client.
522+
// this does not really make any sense either, might equally well change the
523+
// api into something that is not broken by design.
524+
closeQuietlyIfCloseable( ioResourceIter );
519525
ioResourceIter = null;
520526
}
521527
}
@@ -587,6 +593,33 @@ private String normalizedForDuplicateCheck(ArchiveEntry entry){
587593

588594
}
589595

596+
private static void closeIfCloseable( Object resource )
597+
throws IOException
598+
{
599+
if ( resource == null )
600+
{
601+
return;
602+
}
603+
if ( resource instanceof Closeable )
604+
{
605+
( (Closeable) resource ).close();
606+
}
607+
608+
}
609+
610+
private static void closeQuietlyIfCloseable( Object resource )
611+
{
612+
try
613+
{
614+
closeIfCloseable( resource );
615+
}
616+
catch ( IOException e )
617+
{
618+
throw new RuntimeException( e );
619+
}
620+
}
621+
622+
590623
public Map<String, ArchiveEntry> getFiles()
591624
{
592625
try
@@ -1007,14 +1040,13 @@ protected void cleanUp()
10071040
{
10081041
resource = ( (PlexusIoProxyResourceCollection) resource ).getSrc();
10091042
}
1010-
if ( resource instanceof Closeable )
1011-
{
1012-
( (Closeable) resource ).close();
1013-
}
1043+
1044+
closeIfCloseable( resource );
10141045
}
10151046
resources.clear();
10161047
}
10171048

1049+
10181050
protected abstract void execute()
10191051
throws ArchiverException, IOException;
10201052

0 commit comments

Comments
 (0)