You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/07/24 17:49:47 UTC
svn commit: r1365143 -
/lucene/dev/branches/lucene2510/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java
Author: uschindler
Date: Tue Jul 24 15:49:46 2012
New Revision: 1365143
URL: http://svn.apache.org/viewvc?rev=1365143&view=rev
Log:
LUCENE-2510: Some cleanup in the new service class iterator + better messages
Modified:
lucene/dev/branches/lucene2510/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java
Modified: lucene/dev/branches/lucene2510/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2510/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java?rev=1365143&r1=1365142&r2=1365143&view=diff
==============================================================================
--- lucene/dev/branches/lucene2510/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java (original)
+++ lucene/dev/branches/lucene2510/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java Tue Jul 24 15:49:46 2012
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.ServiceConfigurationError;
@@ -61,7 +62,7 @@ public final class SPIClassIterator<S> i
try {
this.profilesEnum = loader.getResources(META_INF_SERVICES + clazz.getName());
} catch (IOException ioe) {
- throw new ServiceConfigurationError("Error loading SPI classes.", ioe);
+ throw new ServiceConfigurationError("Error loading SPI profiles for type " + clazz.getName() + " from classpath", ioe);
}
this.linesIterator = Collections.<String>emptySet().iterator();
}
@@ -74,8 +75,8 @@ public final class SPIClassIterator<S> i
} else {
lines = new ArrayList<String>();
}
+ final URL url = profilesEnum.nextElement();
try {
- final URL url = profilesEnum.nextElement();
final InputStream in = url.openStream();
IOException priorE = null;
try {
@@ -96,7 +97,7 @@ public final class SPIClassIterator<S> i
IOUtils.closeWhileHandlingException(priorE, in);
}
} catch (IOException ioe) {
- throw new ServiceConfigurationError("Error loading SPI classes.", ioe);
+ throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
}
if (!lines.isEmpty()) {
this.linesIterator = lines.iterator();
@@ -120,10 +121,11 @@ public final class SPIClassIterator<S> i
assert linesIterator.hasNext();
final String c = linesIterator.next();
try {
- // don't initialize the class:
+ // don't initialize the class (pass false as 2nd parameter):
return Class.forName(c, false, loader).asSubclass(clazz);
} catch (ClassNotFoundException cnfe) {
- throw new ServiceConfigurationError("SPI class not found: " + c);
+ throw new ServiceConfigurationError(String.format(Locale.ROOT, "A SPI class of type %s with classname %s does not exist, "+
+ "please fix the file '%s%s' in your classpath.", clazz.getName(), c, META_INF_SERVICES, clazz.getName()));
}
}