...
Example
Here's an example. When working on SocketMessageWriter.writeHandshakeMessage
I wondered if the clientVersion
parameter could ever be null
. Here we're testing for null
. Could this null-check be eliminated?
To find out, I annotated the clientVersion
parameter to writeHandshakeMessage
this way:
...
…where I find this call-site passing a null
for clientVersion
:
Since I didn't want to change that call-site, and I didn't want to squander my analysis work, I marked the parameter @Nullable
:
public void writeHandshakeMessage(DataOutputStream dos, byte type, String p_msg,
@Nullable KnownVersion clientVersion, byte endpointType, int queueSize)
throws IOException {
Now it's clear, without the need to look at the call tree, that this parameter can be null
. So the null-check is important and should remain.
I could've found this without the @NotNull
annotation and IDE support. But in this case, I didn't find it until I leveraged the IDE supportthat support. I was able to leave behind a clue for my fellow maintainers. I'm hoping that clue might save them a little bit of work.