Minus 16 calls to getMessage

Adds *Exception(Throwable cause) constructors and calls them where appropriate
thus getting rid of 16 instances of calling getMessage and eliminating the risk
of loosing exception context.

Fixes ElasticsearchTimeoutException along the way (used to discard the
parameter args in the (String message, Object... args) constructor, passes it
up to super now.

Relates to #10021
This commit is contained in:
Isabel Drost-Fromm 2015-09-13 20:11:34 +02:00
parent 6d3dd727c2
commit 5fbf49a0fb
17 changed files with 30 additions and 28 deletions

View File

@ -42,15 +42,6 @@ public class ElasticsearchCorruptionException extends IOException {
* @param ex the exception cause
*/
public ElasticsearchCorruptionException(Throwable ex) {
this(ex.getMessage());
if (ex != null) {
this.setStackTrace(ex.getStackTrace());
}
Throwable[] suppressed = ex.getSuppressed();
if (suppressed != null) {
for (Throwable supressedExc : suppressed) {
addSuppressed(supressedExc);
}
}
super(ex);
}
}

View File

@ -51,6 +51,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
private static final Map<Class<? extends ElasticsearchException>, ElasticsearchExceptionHandle> CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE;
private final Map<String, List<String>> headers = new HashMap<>();
public ElasticsearchException(Throwable cause) {
super(cause);
}
/**
* Construct a <code>ElasticsearchException</code> with the specified detail message.
*

View File

@ -33,8 +33,12 @@ public class ElasticsearchTimeoutException extends ElasticsearchException {
super(in);
}
public ElasticsearchTimeoutException(Throwable cause) {
super(cause);
}
public ElasticsearchTimeoutException(String message, Object... args) {
super(message);
super(message, args);
}
public ElasticsearchTimeoutException(String message, Throwable cause, Object... args) {

View File

@ -47,14 +47,14 @@ public final class ExceptionsHelper {
if (t instanceof RuntimeException) {
return (RuntimeException) t;
}
return new ElasticsearchException(t.getMessage(), t);
return new ElasticsearchException(t);
}
public static ElasticsearchException convertToElastic(Throwable t) {
if (t instanceof ElasticsearchException) {
return (ElasticsearchException) t;
}
return new ElasticsearchException(t.getMessage(), t);
return new ElasticsearchException(t);
}
public static RestStatus status(Throwable t) {
@ -160,7 +160,7 @@ public final class ExceptionsHelper {
main = useOrSuppress(main, ex);
}
if (main != null) {
throw new ElasticsearchException(main.getMessage(), main);
throw new ElasticsearchException(main);
}
}

View File

@ -69,7 +69,7 @@ public abstract class AdapterActionFuture<T, L> extends BaseFuture<T> implements
try {
return get(timeout, unit);
} catch (TimeoutException e) {
throw new ElasticsearchTimeoutException(e.getMessage());
throw new ElasticsearchTimeoutException(e);
} catch (InterruptedException e) {
throw new IllegalStateException("Future got interrupted", e);
} catch (ExecutionException e) {

View File

@ -106,7 +106,7 @@ class TypeConverterBindingProcessor extends AbstractProcessor {
try {
return Class.forName(value);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
throw new RuntimeException(e);
}
}
@ -135,7 +135,7 @@ class TypeConverterBindingProcessor extends AbstractProcessor {
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getTargetException().getMessage());
throw new RuntimeException(e.getTargetException());
}
}

View File

@ -244,7 +244,7 @@ public class Analysis {
return loadWordList(reader, "#");
} catch (IOException ioe) {
String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage());
throw new IllegalArgumentException(message);
throw new IllegalArgumentException(message, ioe);
}
}
@ -291,7 +291,7 @@ public class Analysis {
return FileSystemUtils.newBufferedReader(path.toUri().toURL(), StandardCharsets.UTF_8);
} catch (IOException ioe) {
String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, ioe.getMessage());
throw new IllegalArgumentException(message);
throw new IllegalArgumentException(message, ioe);
}
}

View File

@ -62,7 +62,7 @@ public class HyphenationCompoundWordTokenFilterFactory extends AbstractCompoundW
try {
hyphenationTree = HyphenationCompoundWordTokenFilter.getHyphenationTree(new InputSource(Files.newInputStream(hyphenationPatternsFile)));
} catch (Exception e) {
throw new IllegalArgumentException("Exception while reading hyphenation_patterns_path: " + e.getMessage());
throw new IllegalArgumentException("Exception while reading hyphenation_patterns_path.", e);
}
}

View File

@ -78,7 +78,7 @@ public abstract class AbstractIndexFieldData<FD extends AtomicFieldData> extends
if (e instanceof ElasticsearchException) {
throw (ElasticsearchException) e;
} else {
throw new ElasticsearchException(e.getMessage(), e);
throw new ElasticsearchException(e);
}
}
}

View File

@ -70,7 +70,7 @@ public abstract class AbstractIndexOrdinalsFieldData extends AbstractIndexFieldD
if (e instanceof ElasticsearchException) {
throw (ElasticsearchException) e;
} else {
throw new ElasticsearchException(e.getMessage(), e);
throw new ElasticsearchException(e);
}
}
}

View File

@ -146,7 +146,7 @@ public class ParentChildIndexFieldData extends AbstractIndexFieldData<AtomicPare
if (e instanceof ElasticsearchException) {
throw (ElasticsearchException) e;
} else {
throw new ElasticsearchException(e.getMessage(), e);
throw new ElasticsearchException(e);
}
}
}

View File

@ -73,7 +73,7 @@ public class SortedSetDVOrdinalsIndexFieldData extends DocValuesIndexFieldData i
if (e instanceof ElasticsearchException) {
throw (ElasticsearchException) e;
} else {
throw new ElasticsearchException(e.getMessage(), e);
throw new ElasticsearchException(e);
}
}
}

View File

@ -134,7 +134,7 @@ public class LeafIndexLookup extends MinimalMap<String, IndexField> {
indexField = new IndexField(stringField, this);
indexFields.put(stringField, indexField);
} catch (IOException e) {
throw new ElasticsearchException(e.getMessage());
throw new ElasticsearchException(e);
}
}
return indexField;

View File

@ -59,7 +59,7 @@ public class PlainTransportFuture<V extends TransportResponse> extends BaseFutur
try {
return get(timeout, unit);
} catch (TimeoutException e) {
throw new ElasticsearchTimeoutException(e.getMessage());
throw new ElasticsearchTimeoutException(e);
} catch (InterruptedException e) {
throw new IllegalStateException("Future got interrupted", e);
} catch (ExecutionException e) {

View File

@ -31,7 +31,7 @@ import java.io.IOException;
public class ResponseHandlerFailureTransportException extends TransportException {
public ResponseHandlerFailureTransportException(Throwable cause) {
super(cause.getMessage(), cause);
super(cause);
}
public ResponseHandlerFailureTransportException(StreamInput in) throws IOException {

View File

@ -28,6 +28,10 @@ import java.io.IOException;
*
*/
public class TransportException extends ElasticsearchException {
public TransportException(Throwable cause) {
super(cause);
}
public TransportException(StreamInput in) throws IOException {
super(in);
}

View File

@ -187,7 +187,7 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new ElasticsearchException(e.getMessage(), e);
throw new ElasticsearchException(e);
}
}
}