@@ -516,6 +516,12 @@ else if ( o instanceof PlexusIoResourceCollection )
516
516
}
517
517
else
518
518
{
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 );
519
525
ioResourceIter = null ;
520
526
}
521
527
}
@@ -587,6 +593,33 @@ private String normalizedForDuplicateCheck(ArchiveEntry entry){
587
593
588
594
}
589
595
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
+
590
623
public Map <String , ArchiveEntry > getFiles ()
591
624
{
592
625
try
@@ -1007,14 +1040,13 @@ protected void cleanUp()
1007
1040
{
1008
1041
resource = ( (PlexusIoProxyResourceCollection ) resource ).getSrc ();
1009
1042
}
1010
- if ( resource instanceof Closeable )
1011
- {
1012
- ( (Closeable ) resource ).close ();
1013
- }
1043
+
1044
+ closeIfCloseable ( resource );
1014
1045
}
1015
1046
resources .clear ();
1016
1047
}
1017
1048
1049
+
1018
1050
protected abstract void execute ()
1019
1051
throws ArchiverException , IOException ;
1020
1052
0 commit comments