Skip to content

Commit 96f283c

Browse files
committed
Rename writeThrowable to writeException
This commit renames writeThrowable to writeException. The situation here stems from the fact that the StreamOutput method for serializing Exceptions needs to accept Throwables too as Throwables can be the cause of serialized Exceptions. Yet, we do not serialize Throwables in the Error sub-hierarchy in a way that they can be deserialized into their initial type. This leads to an asymmetry in the StreamOutput method for serializing Exceptions and the StreamInput method for writing Excpetions. Namely, the former will accept Throwables but the latter will only return Exceptions. A goal with the stream methods has always been symmetry in the method names so that serialization/deserialization routines appear symmetrical in code. It is this asymmetry on the input/output types for Exceptions on StreamOutput/StreamInput that clashes with the desired symmetry of naming. Despite this, we should favor symmetry in the naming of the methods. This commit renames StreamOutput#writeThrowable to StreamOutput#writeException which leaves us with Exception StreamInput#readException and void StreamOutput#writeException(Throwable).
1 parent ebe6169 commit 96f283c

File tree

26 files changed

+30
-30
lines changed

26 files changed

+30
-30
lines changed

core/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public Throwable getRootCause() {
204204
@Override
205205
public void writeTo(StreamOutput out) throws IOException {
206206
out.writeOptionalString(this.getMessage());
207-
out.writeThrowable(this.getCause());
207+
out.writeException(this.getCause());
208208
writeStackTraces(this, out);
209209
out.writeVInt(headers.size());
210210
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
@@ -435,7 +435,7 @@ public static <T extends Throwable> T writeStackTraces(T throwable, StreamOutput
435435
Throwable[] suppressed = throwable.getSuppressed();
436436
out.writeVInt(suppressed.length);
437437
for (Throwable t : suppressed) {
438-
out.writeThrowable(t);
438+
out.writeException(t);
439439
}
440440
return throwable;
441441
}

core/src/main/java/org/elasticsearch/action/TaskOperationFailure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public TaskOperationFailure(StreamInput in) throws IOException {
6868
public void writeTo(StreamOutput out) throws IOException {
6969
out.writeString(nodeId);
7070
out.writeLong(taskId);
71-
out.writeThrowable(reason);
71+
out.writeException(reason);
7272
RestStatus.writeTo(out, status);
7373
}
7474

core/src/main/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoresResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void writeTo(StreamOutput out) throws IOException {
189189
allocationStatus.writeTo(out);
190190
if (storeException != null) {
191191
out.writeBoolean(true);
192-
out.writeThrowable(storeException);
192+
out.writeException(storeException);
193193
} else {
194194
out.writeBoolean(false);
195195
}

core/src/main/java/org/elasticsearch/action/bulk/BulkItemResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void writeTo(StreamOutput out) throws IOException {
115115
out.writeString(getIndex());
116116
out.writeString(getType());
117117
out.writeOptionalString(getId());
118-
out.writeThrowable(getCause());
118+
out.writeException(getCause());
119119
}
120120

121121

core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void writeTo(StreamOutput out) throws IOException {
100100
out.writeString(index);
101101
out.writeOptionalString(type);
102102
out.writeString(id);
103-
out.writeThrowable(exception);
103+
out.writeException(exception);
104104
}
105105

106106
public Exception getFailure() {

core/src/main/java/org/elasticsearch/action/ingest/SimulateDocumentBaseResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void writeTo(StreamOutput out) throws IOException {
6363
ingestDocument.writeTo(out);
6464
} else {
6565
out.writeBoolean(true);
66-
out.writeThrowable(failure);
66+
out.writeException(failure);
6767
}
6868
}
6969

core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void writeTo(StreamOutput out) throws IOException {
6868
ingestDocument.writeTo(out);
6969
} else {
7070
out.writeBoolean(true);
71-
out.writeThrowable(failure);
71+
out.writeException(failure);
7272
}
7373
}
7474

core/src/main/java/org/elasticsearch/action/search/MultiSearchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void writeTo(StreamOutput out) throws IOException {
101101
response.writeTo(out);
102102
} else {
103103
out.writeBoolean(false);
104-
out.writeThrowable(exception);
104+
out.writeException(exception);
105105
}
106106
}
107107

core/src/main/java/org/elasticsearch/action/search/ShardSearchFailure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void writeTo(StreamOutput out) throws IOException {
148148
}
149149
out.writeString(reason);
150150
RestStatus.writeTo(out, status);
151-
out.writeThrowable(cause);
151+
out.writeException(cause);
152152
}
153153

154154
@Override

core/src/main/java/org/elasticsearch/action/support/DefaultShardOperationFailedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void writeTo(StreamOutput out) throws IOException {
111111
out.writeString(index);
112112
}
113113
out.writeVInt(shardId);
114-
out.writeThrowable(reason);
114+
out.writeException(reason);
115115
RestStatus.writeTo(out, status);
116116
}
117117

core/src/main/java/org/elasticsearch/action/support/replication/ReplicationResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void readFrom(StreamInput in) throws IOException {
260260
public void writeTo(StreamOutput out) throws IOException {
261261
shardId.writeTo(out);
262262
out.writeOptionalString(nodeId);
263-
out.writeThrowable(cause);
263+
out.writeException(cause);
264264
RestStatus.writeTo(out, status);
265265
out.writeBoolean(primary);
266266
}

core/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void writeTo(StreamOutput out) throws IOException {
100100
out.writeString(index);
101101
out.writeOptionalString(type);
102102
out.writeString(id);
103-
out.writeThrowable(cause);
103+
out.writeException(cause);
104104
}
105105
}
106106

core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public void writeTo(StreamOutput out) throws IOException {
437437
shardRouting.writeTo(out);
438438
sourceShardRouting.writeTo(out);
439439
out.writeString(message);
440-
out.writeThrowable(failure);
440+
out.writeException(failure);
441441
}
442442

443443
@Override

core/src/main/java/org/elasticsearch/cluster/routing/UnassignedInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void writeTo(StreamOutput out) throws IOException {
167167
// Do not serialize unassignedTimeNanos as System.nanoTime() cannot be compared across different JVMs
168168
out.writeBoolean(delayed);
169169
out.writeOptionalString(message);
170-
out.writeThrowable(failure);
170+
out.writeException(failure);
171171
out.writeVInt(failedAllocations);
172172
}
173173

core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* This exception can be used to wrap a given, not serializable exception
30-
* to serialize via {@link StreamOutput#writeThrowable(Throwable)}.
30+
* to serialize via {@link StreamOutput#writeException(Throwable)}.
3131
* This class will preserve the stacktrace as well as the suppressed exceptions of
3232
* the throwable it was created with instead of it's own. The stacktrace has no indication
3333
* of where this exception was created.

core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public void writeOptionalWriteable(@Nullable Writeable writeable) throws IOExcep
631631
}
632632
}
633633

634-
public void writeThrowable(Throwable throwable) throws IOException {
634+
public void writeException(Throwable throwable) throws IOException {
635635
if (throwable == null) {
636636
writeBoolean(false);
637637
} else {
@@ -739,7 +739,7 @@ public void writeThrowable(Throwable throwable) throws IOException {
739739
writeOptionalString(throwable.getMessage());
740740
}
741741
if (writeCause) {
742-
writeThrowable(throwable.getCause());
742+
writeException(throwable.getCause());
743743
}
744744
ElasticsearchException.writeStackTraces(throwable, this);
745745
}

core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public void writeTo(StreamOutput out) throws IOException {
298298
out.writeBoolean(primary);
299299
if (storeException != null) {
300300
out.writeBoolean(true);
301-
out.writeThrowable(storeException);
301+
out.writeException(storeException);
302302
} else {
303303
out.writeBoolean(false);
304304
}

core/src/main/java/org/elasticsearch/index/store/Store.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ public void markStoreCorrupted(IOException exception) throws IOException {
13371337
try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) {
13381338
CodecUtil.writeHeader(output, CODEC, VERSION);
13391339
BytesStreamOutput out = new BytesStreamOutput();
1340-
out.writeThrowable(exception);
1340+
out.writeException(exception);
13411341
BytesReference bytes = out.bytes();
13421342
output.writeVInt(bytes.length());
13431343
BytesRef ref = bytes.toBytesRef();

core/src/main/java/org/elasticsearch/repositories/VerificationFailure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void readFrom(StreamInput in) throws IOException {
5959
@Override
6060
public void writeTo(StreamOutput out) throws IOException {
6161
out.writeOptionalString(nodeId);
62-
out.writeThrowable(cause);
62+
out.writeException(cause);
6363
}
6464

6565
public static VerificationFailure readNode(StreamInput in) throws IOException {

core/src/main/java/org/elasticsearch/transport/TcpTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ public void sendErrorResponse(Version nodeVersion, Channel channel, final Except
940940
stream.setVersion(nodeVersion);
941941
RemoteTransportException tx = new RemoteTransportException(
942942
nodeName(), new InetSocketTransportAddress(getLocalAddress(channel)), action, error);
943-
stream.writeThrowable(tx);
943+
stream.writeException(tx);
944944
byte status = 0;
945945
status = TransportStatus.setResponse(status);
946946
status = TransportStatus.setError(status);

core/src/main/java/org/elasticsearch/transport/local/LocalTransportChannel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void sendResponse(Exception exception) throws IOException {
9696
writeResponseExceptionHeader(stream);
9797
RemoteTransportException tx = new RemoteTransportException(targetTransport.nodeName(),
9898
targetTransport.boundAddress().boundAddresses()[0], action, exception);
99-
stream.writeThrowable(tx);
99+
stream.writeException(tx);
100100
sendResponseData(BytesReference.toBytes(stream.bytes()));
101101
sourceTransportServiceAdapter.onResponseSent(requestId, action, exception);
102102
}

core/src/test/java/org/elasticsearch/ESExceptionTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void testToXContent() throws IOException {
301301
public void testSerializeElasticsearchException() throws IOException {
302302
BytesStreamOutput out = new BytesStreamOutput();
303303
ParsingException ex = new ParsingException(1, 2, "foobar", null);
304-
out.writeThrowable(ex);
304+
out.writeException(ex);
305305

306306
StreamInput in = out.bytes().streamInput();
307307
ParsingException e = in.readException();
@@ -315,7 +315,7 @@ public void testSerializeUnknownException() throws IOException {
315315
BytesStreamOutput out = new BytesStreamOutput();
316316
ParsingException parsingException = new ParsingException(1, 2, "foobar", null);
317317
final Exception ex = new UnknownException("eggplant", parsingException);
318-
out.writeThrowable(ex);
318+
out.writeException(ex);
319319

320320
StreamInput in = out.bytes().streamInput();
321321
Throwable throwable = in.readException();
@@ -354,7 +354,7 @@ public void testWriteThrowable() throws IOException {
354354
for (final Exception cause : causes) {
355355
BytesStreamOutput out = new BytesStreamOutput();
356356
ElasticsearchException ex = new ElasticsearchException("topLevel", cause);
357-
out.writeThrowable(ex);
357+
out.writeException(ex);
358358
StreamInput in = out.bytes().streamInput();
359359
ElasticsearchException e = in.readException();
360360
assertEquals(e.getMessage(), ex.getMessage());

core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public TestException(StreamInput in) throws IOException {
222222
private <T extends Exception> T serialize(T exception) throws IOException {
223223
ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersion(random()), exception);
224224
BytesStreamOutput out = new BytesStreamOutput();
225-
out.writeThrowable(exception);
225+
out.writeException(exception);
226226
StreamInput in = out.bytes().streamInput();
227227
return in.readException();
228228
}

modules/lang-mustache/src/main/java/org/elasticsearch/action/search/template/MultiSearchTemplateResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void writeTo(StreamOutput out) throws IOException {
9696
response.writeTo(out);
9797
} else {
9898
out.writeBoolean(false);
99-
out.writeThrowable(exception);
99+
out.writeException(exception);
100100
}
101101
}
102102

modules/percolator/src/main/java/org/elasticsearch/percolator/MultiPercolateResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void writeTo(StreamOutput out) throws IOException {
172172
response.writeTo(out);
173173
} else {
174174
out.writeBoolean(false);
175-
out.writeThrowable(exception);
175+
out.writeException(exception);
176176
}
177177
}
178178
}

test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ public void readFrom(StreamInput in) throws IOException {
682682

683683
@Override
684684
public void writeTo(StreamOutput out) throws IOException {
685-
out.writeThrowable(exception);
685+
out.writeException(exception);
686686
}
687687

688688
}

0 commit comments

Comments
 (0)