33import java .io .IOException ;
44import java .nio .file .Path ;
55import java .util .ArrayList ;
6- import java .util .List ;
7- import java .util .ResourceBundle ;
6+ import java .util .Collection ;
7+ import java .util .Collections ;
88import java .util .Map .Entry ;
9+ import java .util .ResourceBundle ;
910import java .util .concurrent .CountDownLatch ;
1011import java .util .concurrent .ExecutorService ;
1112import java .util .concurrent .Executors ;
@@ -151,10 +152,8 @@ public void isValid(final Bag bag, final boolean ignoreHiddenFiles) throws IOExc
151152 void checkHashes (final Manifest manifest ) throws CorruptChecksumException , InterruptedException , VerificationException {
152153 final CountDownLatch latch = new CountDownLatch ( manifest .getFileToChecksumMap ().size ());
153154
154- //TODO maybe return all of these at some point...
155- //if that is ever the case make sure to use Collections.synchronizedCollection(new ArrayList<>())
156- //we aren't doing it now because it is a huge performance hit for little value
157- final List <Exception > exceptions = new ArrayList <>();
155+ //TODO maybe return all of these at some point...
156+ final Collection <Exception > exceptions = Collections .synchronizedCollection (new ArrayList <>());
158157
159158 for (final Entry <Path , String > entry : manifest .getFileToChecksumMap ().entrySet ()){
160159 executor .execute (new CheckManifestHashesTask (entry , manifest .getAlgorithm ().getMessageDigestName (), latch , exceptions ));
@@ -163,7 +162,7 @@ void checkHashes(final Manifest manifest) throws CorruptChecksumException, Inter
163162 latch .await ();
164163
165164 if (!exceptions .isEmpty ()){
166- final Exception e = exceptions .get ( 0 );
165+ final Exception e = exceptions .iterator (). next ( );
167166 if (e instanceof CorruptChecksumException ){
168167 logger .debug (messages .getString ("checksums_not_matching_error" ), exceptions .size ());
169168 throw (CorruptChecksumException )e ;
0 commit comments