Elffuss BraidHub

kikocis/java-driver public

JAVA-1209: ProtocolOptions.getProtocolVersion() should return null
instead of throwing NPE if Cluster has not been init'd
Changeset7beeb2fc4b47adaceffa09b458247e76457ea290874c74e2fc6065e18163677a
AuthorDmitry Murashenkov <dmitry.murashenkov@mind.com> · 2016-06-08 13:10 +03:00
CommitterDmitry Murashenkov <dmitry.murashenkov@mind.com> · 2016-06-08 13:19 +03:00
Parents47f8bf44bd1e

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -2,6 +2,7 @@
22
33 ### 3.0.3 (in progress)
44
5+- [bug] JAVA-1209: ProtocolOptions.getProtocolVersion() should return null instead of throwing NPE if Cluster has not been init'd
56
67 ### 3.0.2
78
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolOptions.java +1 −1
@@ -165,7 +165,7 @@
165165 * nodes that do not support this protocol version will be ignored.
166166 */
167167 public ProtocolVersion getProtocolVersion() {
168- return manager.connectionFactory.protocolVersion;
168+ return manager == null || manager.connectionFactory == null ? null : manager.connectionFactory.protocolVersion;
169169 }
170170
171171 /**
added driver-core/src/test/java/com/datastax/driver/core/ProtocolOptionsTest.java +42 −0
@@ -0,0 +1,42 @@
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;
17+
18+import org.testng.annotations.Test;
19+
20+import static org.testng.Assert.assertNotNull;
21+import static org.testng.Assert.assertNull;
22+
23+public class ProtocolOptionsTest extends CCMTestsSupport {
24+
25+ /**
26+ * @jira_ticket JAVA-1209
27+ */
28+ @Test(groups = "unit")
29+ public void getProtocolVersion_should_return_null_if_not_connected() {
30+ Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
31+ assertNull(cluster.getConfiguration().getProtocolOptions().getProtocolVersion());
32+ }
33+
34+ /**
35+ * @jira_ticket JAVA-1209
36+ */
37+ @Test(groups = "short")
38+ public void getProtocolVersion_should_return_version() throws InterruptedException {
39+ ProtocolVersion version = cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
40+ assertNotNull(version);
41+ }
42+}