kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 1a48a06341f592495d29b131e4c1783d855e157a15c8b7a3f5c1b1bc5f64ace4 |
|---|---|
| Author | Dmitry Murashenkov <dmitry.murashenkov@mind.com> · 2016-06-08 11:10 +03:00 |
| Committer | Dmitry Murashenkov <dmitry.murashenkov@mind.com> · 2016-06-09 11:24 +03:00 |
| Parents | 47f8bf44bd1e |
3 files changed
modified changelog/README.md +1 −0
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | ### 3.0.3 (in progress) |
| 4 | 4 | |
| 5 | +- [bug] JAVA-1139: ConnectionException.getMessage() throws NPE if address is null | |
| 5 | 6 | |
| 6 | 7 | ### 3.0.2 |
| 7 | 8 |
modified driver-core/src/main/java/com/datastax/driver/core/exceptions/ConnectionException.java +2 −2
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | @Override |
| 42 | 42 | public InetAddress getHost() { |
| 43 | - return address.getAddress(); | |
| 43 | + return address == null ? null : address.getAddress(); | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | @Override |
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 | |
| 51 | 51 | @Override |
| 52 | 52 | public String getMessage() { |
| 53 | - return String.format("[%s] %s", getHost(), getRawMessage()); | |
| 53 | + return address == null ? getRawMessage() : String.format("[%s] %s", address, getRawMessage()); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | @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 | +} |