3131import java .util .ArrayList ;
3232import java .util .Enumeration ;
3333import java .util .HashMap ;
34+ import java .util .HashSet ;
3435import java .util .Iterator ;
3536import java .util .List ;
3637import java .util .Map ;
38+ import java .util .Set ;
3739import java .util .zip .ZipEntry ;
3840import java .util .zip .ZipFile ;
3941
@@ -61,28 +63,30 @@ public class ClassPathManager {
6163
6264 private static final int MAXOPEN_DEFAULT = 1000 ;
6365
64- private List <Entry > entries ;
66+ private final List <Entry > entries ;
67+
68+ private final Set <String > notFound = new HashSet <>(100 );
6569
6670 // In order to control how many open files we have, we maintain a list.
6771 // The max number is configured through the property:
6872 // org.aspectj.weaver.openarchives
6973 // and it defaults to 1000
70- private List <ZipFile > openArchives = new ArrayList <>();
74+ private final List <ZipFile > openArchives = new ArrayList <>();
7175
7276 static {
7377 String openzipsString = getSystemPropertyWithoutSecurityException ("org.aspectj.weaver.openarchives" ,
7478 Integer .toString (MAXOPEN_DEFAULT ));
7579 maxOpenArchives = Integer .parseInt (openzipsString );
7680 if (maxOpenArchives < 20 ) {
77- maxOpenArchives = 1000 ;
81+ maxOpenArchives = MAXOPEN_DEFAULT ;
7882 }
7983 }
8084
8185 public ClassPathManager (List <String > classpath , IMessageHandler handler ) {
8286 if (trace .isTraceEnabled ()) {
8387 trace .enter ("<init>" , this , new Object [] { classpath ==null ?"null" :classpath .toString (), handler });
8488 }
85- entries = new ArrayList <>();
89+ entries = new ArrayList <>(classpath == null ? 1 : classpath . size () );
8690 for (String classpathEntry : classpath ) {
8791 addPath (classpathEntry ,handler );
8892 }
@@ -92,6 +96,7 @@ public ClassPathManager(List<String> classpath, IMessageHandler handler) {
9296 }
9397
9498 protected ClassPathManager () {
99+ entries = null ;
95100 }
96101
97102 public void addPath (String name , IMessageHandler handler ) {
@@ -127,6 +132,9 @@ public ClassFile find(UnresolvedType type) {
127132 trace .enter ("find" , this , type );
128133 }
129134 String name = type .getName ();
135+ if (notFound .contains (name )) {
136+ return null ;
137+ }
130138 for (Iterator <Entry > i = entries .iterator (); i .hasNext ();) {
131139 Entry entry = i .next ();
132140 try {
@@ -151,6 +159,7 @@ public ClassFile find(UnresolvedType type) {
151159 if (trace .isTraceEnabled ()) {
152160 trace .exit ("find" , null );
153161 }
162+ notFound .add (name );
154163 return null ;
155164 }
156165
@@ -181,9 +190,9 @@ abstract static class Entry {
181190
182191 static class ByteBasedClassFile extends ClassFile {
183192
184- private byte [] bytes ;
193+ private final byte [] bytes ;
185194 private ByteArrayInputStream bais ;
186- private String path ;
195+ private final String path ;
187196
188197 public ByteBasedClassFile (byte [] bytes , String path ) {
189198 this .bytes = bytes ;
@@ -215,7 +224,7 @@ public void close() {
215224 }
216225
217226 static class FileClassFile extends ClassFile {
218- private File file ;
227+ private final File file ;
219228 private FileInputStream fis ;
220229
221230 public FileClassFile (File file ) {
@@ -247,7 +256,7 @@ public String getPath() {
247256 }
248257
249258 class DirEntry extends Entry {
250- private String dirPath ;
259+ private final String dirPath ;
251260
252261 public DirEntry (File dir ) {
253262 this .dirPath = dir .getPath ();
@@ -273,8 +282,8 @@ public String toString() {
273282 }
274283
275284 static class ZipEntryClassFile extends ClassFile {
276- private ZipEntry entry ;
277- private ZipFileEntry zipFile ;
285+ private final ZipEntry entry ;
286+ private final ZipFileEntry zipFile ;
278287 private InputStream is ;
279288
280289 public ZipEntryClassFile (ZipFileEntry zipFile , ZipEntry entry ) {
@@ -407,7 +416,7 @@ private synchronized void buildPackageMap() {
407416 class TypeIdentifier extends SimpleFileVisitor <Path > {
408417
409418 // What are we looking for?
410- private String name ;
419+ private final String name ;
411420
412421 // If set, where did we find it?
413422 public Path found ;
@@ -586,7 +595,7 @@ public String toString() {
586595 }
587596
588597 /* private */ static boolean hasClassExtension (String name ) {
589- return name .toLowerCase ().endsWith (( ".class" ) );
598+ return name .toLowerCase ().endsWith (".class" );
590599 }
591600
592601 public void closeArchives () {
0 commit comments