Skip to content

Commit 49feb65

Browse files
authored
Remove unused ConnectTransportException#node (#80944)
`ConnectTransportException#node` is only used in a couple of assertions in tests, but those assertions are either unnecessary or can be rewritten without it so this field is effectively unused. This commit removes it.
1 parent 2e8a973 commit 49feb65

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

server/src/main/java/org/elasticsearch/transport/ConnectTransportException.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.transport;
1010

11+
import org.elasticsearch.Version;
1112
import org.elasticsearch.cluster.node.DiscoveryNode;
1213
import org.elasticsearch.common.io.stream.StreamInput;
1314
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -16,8 +17,6 @@
1617

1718
public class ConnectTransportException extends ActionTransportException {
1819

19-
private final DiscoveryNode node;
20-
2120
public ConnectTransportException(DiscoveryNode node, String msg) {
2221
this(node, msg, null, null);
2322
}
@@ -32,21 +31,20 @@ public ConnectTransportException(DiscoveryNode node, String msg, Throwable cause
3231

3332
public ConnectTransportException(DiscoveryNode node, String msg, String action, Throwable cause) {
3433
super(node == null ? null : node.getName(), node == null ? null : node.getAddress(), action, msg, cause);
35-
this.node = node;
3634
}
3735

3836
public ConnectTransportException(StreamInput in) throws IOException {
3937
super(in);
40-
node = in.readOptionalWriteable(DiscoveryNode::new);
38+
if (in.getVersion().before(Version.V_8_1_0)) {
39+
in.readOptionalWriteable(DiscoveryNode::new);
40+
}
4141
}
4242

4343
@Override
4444
public void writeTo(StreamOutput out) throws IOException {
4545
super.writeTo(out);
46-
out.writeOptionalWriteable(node);
47-
}
48-
49-
public DiscoveryNode node() {
50-
return node;
46+
if (out.getVersion().before(Version.V_8_1_0)) {
47+
out.writeBoolean(false); // optional & unused node field
48+
}
5149
}
5250
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,10 @@ public void testConnectTransportException() throws IOException {
410410
DiscoveryNode node = new DiscoveryNode("thenode", transportAddress, emptyMap(), emptySet(), Version.CURRENT);
411411
ConnectTransportException ex = serialize(new ConnectTransportException(node, "msg", "action", null));
412412
assertEquals("[][" + transportAddress + "][action] msg", ex.getMessage());
413-
assertEquals(node, ex.node());
414413
assertNull(ex.getCause());
415414

416415
ex = serialize(new ConnectTransportException(node, "msg", "action", new NullPointerException()));
417416
assertEquals("[][" + transportAddress + "][action] msg", ex.getMessage());
418-
assertEquals(node, ex.node());
419417
assertTrue(ex.getCause() instanceof NullPointerException);
420418
}
421419

test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import static java.util.Collections.emptyMap;
8888
import static java.util.Collections.emptySet;
8989
import static org.elasticsearch.transport.TransportService.NOOP_TRANSPORT_INTERCEPTOR;
90+
import static org.hamcrest.Matchers.allOf;
9091
import static org.hamcrest.Matchers.containsString;
9192
import static org.hamcrest.Matchers.empty;
9293
import static org.hamcrest.Matchers.equalTo;
@@ -1721,15 +1722,15 @@ public void handleResponse(StringMessageResponse response) {
17211722
public void handleException(TransportException exp) {
17221723
Throwable cause = ExceptionsHelper.unwrapCause(exp);
17231724
assertThat(cause, instanceOf(ConnectTransportException.class));
1724-
assertThat(((ConnectTransportException) cause).node(), equalTo(nodeA));
1725+
assertThat(cause.getMessage(), allOf(containsString(nodeA.getName()), containsString(nodeA.getAddress().toString())));
17251726
}
17261727
}
17271728
);
17281729

17291730
final ExecutionException e = expectThrows(ExecutionException.class, res::get);
17301731
Throwable cause = ExceptionsHelper.unwrapCause(e.getCause());
17311732
assertThat(cause, instanceOf(ConnectTransportException.class));
1732-
assertThat(((ConnectTransportException) cause).node(), equalTo(nodeA));
1733+
assertThat(cause.getMessage(), allOf(containsString(nodeA.getName()), containsString(nodeA.getAddress().toString())));
17331734

17341735
// wait for the transport to process the sending failure and disconnect from node
17351736
assertBusy(() -> assertFalse(serviceB.nodeConnected(nodeA)));

0 commit comments

Comments
 (0)