From 4c23e64c08c25693d57bdcdca8c0abce891139d1 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 16 Jul 2010 15:22:00 +0000 Subject: [PATCH] SOLR-2003: improve exception message for encoding errors (print filename, etc) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@964832 13f79535-47bb-0310-9956-ffa450edef68 --- solr/src/java/org/apache/solr/core/SolrResourceLoader.java | 5 +++++ solr/src/test/org/apache/solr/core/ResourceLoaderTest.java | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/solr/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/src/java/org/apache/solr/core/SolrResourceLoader.java index e8f037d7935..7b9b646fd31 100644 --- a/solr/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -32,6 +32,8 @@ import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CodingErrorAction; import java.lang.reflect.Constructor; @@ -333,6 +335,9 @@ public class SolrResourceLoader implements ResourceLoader if (word.length()==0) continue; lines.add(word); } + } catch (CharacterCodingException ex) { + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, + "Error loading resource (wrong encoding?): " + resource, ex); } finally { if (input != null) input.close(); diff --git a/solr/src/test/org/apache/solr/core/ResourceLoaderTest.java b/solr/src/test/org/apache/solr/core/ResourceLoaderTest.java index 41364613bcc..6f350023e7f 100644 --- a/solr/src/test/org/apache/solr/core/ResourceLoaderTest.java +++ b/solr/src/test/org/apache/solr/core/ResourceLoaderTest.java @@ -31,7 +31,7 @@ import org.apache.solr.util.plugin.SolrCoreAware; import java.io.File; import java.io.InputStream; -import java.nio.charset.MalformedInputException; +import java.nio.charset.CharacterCodingException; import java.util.Arrays; import java.util.List; @@ -126,6 +126,8 @@ public class ResourceLoaderTest extends TestCase try { List lines = loader.getLines(wrongEncoding); fail(); - } catch (MalformedInputException expected) {} + } catch (SolrException expected) { + assertTrue(expected.getCause() instanceof CharacterCodingException); + } } }