From baa71b943fa6658c9c516ab38e240a4923d20bde Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Tue, 24 Jul 2012 15:49:46 +0000 Subject: [PATCH] LUCENE-2510: Some cleanup in the new service class iterator + better messages git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2510@1365143 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/util/SPIClassIterator.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java b/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java index 620ed33d814..bf181beb225 100644 --- a/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java +++ b/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java @@ -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 implements Iterator> { 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.emptySet().iterator(); } @@ -74,8 +75,8 @@ public final class SPIClassIterator implements Iterator> { } else { lines = new ArrayList(); } + 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 implements Iterator> { 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 implements Iterator> { 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())); } }