mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
a803300431
commit
4c23e64c08
|
@ -32,6 +32,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.nio.charset.CharacterCodingException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.CodingErrorAction;
|
import java.nio.charset.CodingErrorAction;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
@ -333,6 +335,9 @@ public class SolrResourceLoader implements ResourceLoader
|
||||||
if (word.length()==0) continue;
|
if (word.length()==0) continue;
|
||||||
lines.add(word);
|
lines.add(word);
|
||||||
}
|
}
|
||||||
|
} catch (CharacterCodingException ex) {
|
||||||
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||||
|
"Error loading resource (wrong encoding?): " + resource, ex);
|
||||||
} finally {
|
} finally {
|
||||||
if (input != null)
|
if (input != null)
|
||||||
input.close();
|
input.close();
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.solr.util.plugin.SolrCoreAware;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.MalformedInputException;
|
import java.nio.charset.CharacterCodingException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -126,6 +126,8 @@ public class ResourceLoaderTest extends TestCase
|
||||||
try {
|
try {
|
||||||
List<String> lines = loader.getLines(wrongEncoding);
|
List<String> lines = loader.getLines(wrongEncoding);
|
||||||
fail();
|
fail();
|
||||||
} catch (MalformedInputException expected) {}
|
} catch (SolrException expected) {
|
||||||
|
assertTrue(expected.getCause() instanceof CharacterCodingException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue