Elffuss BraidHub

kikocis/java-driver public

Merge remote-tracking branch 'dmitry/java1139' into 3.0.x
Changesetba109c0e72cee0bce42e171d3e8b76879a4427dfb0003987445f5db2bed52a29
Authorolim7t <omichallat+github@gmail.com> · 2016-06-27 11:15 -07:00
Committerolim7t <omichallat+github@gmail.com> · 2016-06-27 11:15 -07:00
Parents493693bdeaa2, 1a48a06341f5

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -10,6 +10,7 @@
1010 - [bug] JAVA-1186: Fix duplicated hosts in DCAwarePolicy warn message.
1111 - [bug] JAVA-1187: Fix warning message when local CL used with RoundRobinPolicy.
1212 - [improvement] JAVA-1175: Warn if DCAwarePolicy configuration is inconsistent.
13+- [bug] JAVA-1139: ConnectionException.getMessage() throws NPE if address is null.
1314
1415
1516 ### 3.0.2
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/ConnectionException.java +2 −2
@@ -40,7 +40,7 @@
4040
4141 @Override
4242 public InetAddress getHost() {
43- return address.getAddress();
43+ return address == null ? null : address.getAddress();
4444 }
4545
4646 @Override
@@ -50,7 +50,7 @@
5050
5151 @Override
5252 public String getMessage() {
53- return String.format("[%s] %s", getHost(), getRawMessage());
53+ return address == null ? getRawMessage() : String.format("[%s] %s", address, getRawMessage());
5454 }
5555
5656 @Override
added driver-core/src/test/java/com/datastax/driver/core/exceptions/ConnectionExceptionTest.java +58 −0
@@ -0,0 +1,58 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core.exceptions;
17+
18+import org.testng.annotations.Test;
19+
20+import java.net.InetSocketAddress;
21+
22+import static org.testng.Assert.assertEquals;
23+import static org.testng.Assert.assertNull;
24+
25+public class ConnectionExceptionTest {
26+
27+ /**
28+ * @jira_ticket JAVA-1139
29+ */
30+ @Test(groups = "unit")
31+ public void getHost_should_return_null_if_address_is_null() {
32+ assertNull(new ConnectionException(null, "Test message").getHost());
33+ }
34+
35+ /**
36+ * @jira_ticket JAVA-1139
37+ */
38+ @Test(groups = "unit")
39+ public void getMessage_should_return_message_if_address_is_null() {
40+ assertEquals(new ConnectionException(null, "Test message").getMessage(), "Test message");
41+ }
42+
43+ /**
44+ * @jira_ticket JAVA-1139
45+ */
46+ @Test(groups = "unit")
47+ public void getMessage_should_return_message_if_address_is_unresolved() {
48+ assertEquals(new ConnectionException(InetSocketAddress.createUnresolved("127.0.0.1", 9042), "Test message").getMessage(), "[127.0.0.1:9042] Test message");
49+ }
50+
51+ /**
52+ * @jira_ticket JAVA-1139
53+ */
54+ @Test(groups = "unit")
55+ public void getMessage_should_return_message_if_address_is_resolved() {
56+ assertEquals(new ConnectionException(new InetSocketAddress("127.0.0.1", 9042), "Test message").getMessage(), "[/127.0.0.1:9042] Test message");
57+ }
58+}