Skip to content

Commit beaad5f

Browse files
olim7tadutra
authored andcommitted
JAVA-2505: Annotate Node.getHostId() as nullable (apache#1350)
1 parent 37545e6 commit beaad5f

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.3.0 (in progress)
66

7+
- [documentation] JAVA-2505: Annotate Node.getHostId() as nullable
78
- [improvement] JAVA-1708: Support DSE "everywhere" replication strategy
89
- [improvement] JAVA-2471: Consider DSE version when parsing the schema
910
- [improvement] JAVA-2444: Add method setRoutingKey(ByteBuffer...) to StatementBuilder

core/revapi.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4816,6 +4816,20 @@
48164816
"old": "field com\\.datastax\\.oss\\.driver\\.api\\.core\\.Version.V.*",
48174817
"annotation": "@edu.umd.cs.findbugs.annotations.NonNull",
48184818
"justification": "Marking constants as non-null doesn't break existing code"
4819+
},
4820+
{
4821+
"code": "java.annotation.removed",
4822+
"old": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.Node::getHostId()",
4823+
"new": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.Node::getHostId()",
4824+
"annotation": "@edu.umd.cs.findbugs.annotations.NonNull",
4825+
"justification": "JAVA-2505: Annotate Node.getHostId() as nullable"
4826+
},
4827+
{
4828+
"code": "java.annotation.added",
4829+
"old": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.Node::getHostId()",
4830+
"new": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.Node::getHostId()",
4831+
"annotation": "@edu.umd.cs.findbugs.annotations.Nullable",
4832+
"justification": "JAVA-2505: Annotate Node.getHostId() as nullable"
48194833
}
48204834
]
48214835
}

core/src/main/java/com/datastax/oss/driver/api/core/metadata/Node.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,26 @@ public interface Node {
184184
* The host ID that is assigned to this node by Cassandra. This value can be used to uniquely
185185
* identify a node even when the underling IP address changes.
186186
*
187-
* <p>This information is always present.
187+
* <p>This information is always present once the session has initialized. However, there is a
188+
* narrow corner case where a driver client can observe a null value: if a {@link
189+
* NodeStateListener} is registered, the <b>very first</b> {@code onUp} call will reference a node
190+
* that has a null id (that node is the initial contact point, and the driver hasn't read host ids
191+
* from {@code system.local} and {@code system.peers} yet). Beyond that point &mdash; including
192+
* any other {@code onUp} call &mdash; the host id will always be present.
193+
*
194+
* <pre>
195+
* CqlSession session = CqlSession.builder()
196+
* .withNodeStateListener(
197+
* new NodeStateListenerBase() {
198+
* &#64;Override
199+
* public void onUp(@NonNull Node node) {
200+
* // node.getHostId() == null for the first invocation only
201+
* }
202+
* })
203+
* .build();
204+
* </pre>
188205
*/
189-
@NonNull
206+
@Nullable
190207
UUID getHostId();
191208

192209
/**

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/DefaultNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public Version getCassandraVersion() {
129129
return cassandraVersion;
130130
}
131131

132-
@NonNull
132+
@Nullable
133133
@Override
134134
public UUID getHostId() {
135135
return hostId;

0 commit comments

Comments
 (0)