Elffuss BraidHub

kikocis/java-driver public

JAVA-656: Fix NPE in ControlConnection.updateLocationInfo.
Changeseta1b64c4681a0a0eb8f6a604b665ba8308c8d504a379cc44ebd46bb776d4c434d
Authortommy stendahl <tommy.stendahl@ericsson.com> · 2015-08-14 08:33 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-10-30 16:48 +01:00
Parents0a81df133747

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -9,6 +9,7 @@
99 - [improvement] JAVA-921: Add SimpleStatement.getValuesCount().
1010 - [bug] JAVA-901: Move call to connection.release() out of cancelHandler.
1111 - [bug] JAVA-960: Avoid race in control connection shutdown.
12+- [bug] JAVA-656: Fix NPE in ControlConnection.updateLocationInfo.
1213
1314
1415 ### 2.0.11
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +9 −2
@@ -587,8 +587,15 @@
587587 if (host == null) {
588588 // We don't know that node, create the Host object but wait until we've set the known
589589 // info before signaling the addition.
590- host = cluster.metadata.add(foundHosts.get(i));
591- isNew = true;
590+ Host newHost = cluster.metadata.newHost(foundHosts.get(i));
591+ Host existing = cluster.metadata.addIfAbsent(newHost);
592+ if (existing == null) {
593+ host = newHost;
594+ isNew = true;
595+ } else {
596+ host = existing;
597+ isNew = false;
598+ }
592599 }
593600 if (dcs.get(i) != null || racks.get(i) != null)
594601 updateLocationInfo(host, dcs.get(i), racks.get(i), isInitialConnection, cluster);
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +10 −3
@@ -282,10 +282,17 @@
282282 this.tokenMap = TokenMap.build(factory, allTokens, keyspaces.values());
283283 }
284284
285+ Host newHost(InetSocketAddress address) {
286+ return new Host(address, cluster.convictionPolicyFactory, cluster);
287+ }
288+
289+ Host addIfAbsent(Host host) {
290+ Host previous = hosts.putIfAbsent(host.getSocketAddress(), host);
291+ return previous == null ? host : null;
292+ }
293+
285294 Host add(InetSocketAddress address) {
286- Host newHost = new Host(address, cluster.convictionPolicyFactory, cluster);
287- Host previous = hosts.putIfAbsent(address, newHost);
288- return previous == null ? newHost : null;
295+ return addIfAbsent(newHost(address));
289296 }
290297
291298 boolean remove(Host host) {