commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1462635 - /commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java
Date Fri, 29 Mar 2013 20:34:30 GMT
Author: chas
Date: Fri Mar 29 20:34:30 2013
New Revision: 1462635

URL: http://svn.apache.org/r1462635
Log:
Fix NullPointerException occuring after encountering non-jar file in classpath

Modified:
    commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java

Modified: commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java?rev=1462635&r1=1462634&r2=1462635&view=diff
==============================================================================
--- commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java
(original)
+++ commons/sandbox/classscan/trunk/api/src/main/java/org/apache/commons/classscan/builtin/JarClassPathElement.java
Fri Mar 29 20:34:30 2013
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
@@ -43,18 +44,24 @@ public class JarClassPathElement impleme
 
     final private URL location;
     private URL[] classPathLocations;
-	
+
 	public JarClassPathElement(URL location) {
 		this.location = location;
 	}
 
 	@Override
-	public Iterator<ClassFile> iterator() {		
-		final JarFile jarFile= getJarFile();		
+	public Iterator<ClassFile> iterator() {
+		final JarFile jarFile= getJarFile();
+		if(jarFile == null) {
+			List<ClassFile> emptyList= Collections.emptyList();
+			return emptyList.iterator();
+		}
+
         final Enumeration<JarEntry> jarEntries = jarFile.entries();
-        
-		return new ClassFileIterator() {			
-			ClassFile getNext() {
+
+		return new ClassFileIterator() {
+			@Override
+            ClassFile getNext() {
 				while(jarEntries.hasMoreElements()) {
 					JarClassFile jcf= new JarClassFile(jarFile, jarEntries.nextElement());
 					if(jcf.getClassName()!=null) {
@@ -71,7 +78,7 @@ public class JarClassPathElement impleme
 		};
 	}
 
-	private JarFile getJarFile() {		
+	private JarFile getJarFile() {
         try {
             JarURLConnection conn = (JarURLConnection) location.openConnection();
             JarFile jf= conn.getJarFile();
@@ -89,7 +96,7 @@ public class JarClassPathElement impleme
 		if(manifest == null) {
 			return;
 		}
-		
+
 		URI resolveLocation;
 		try {
 			resolveLocation = location.toURI();
@@ -97,13 +104,13 @@ public class JarClassPathElement impleme
         	logger.warn("Could not create URI out of {}", location);
         	return;
 		}
-		
+
         Attributes attributes = manifest.getMainAttributes();
         String classPath = attributes.getValue(Attributes.Name.CLASS_PATH);
         if (classPath == null) {
             return;
         }
-        
+
         List<URL> newLocations = new ArrayList<URL>();
 		for (String pathElement : PATH_SPLITTER.split(classPath)) {
             URI resolvedLocation = resolveLocation.resolve(pathElement);
@@ -118,7 +125,7 @@ public class JarClassPathElement impleme
 	}
 
     private static Pattern PATH_SPLITTER = Pattern.compile("\\s+");
-    
+
 	@Override
 	public String getLocation() {
 		return location.toExternalForm();



Mime
View raw message