Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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?

Image Added

To find out, I annotated the clientVersion parameter to writeHandshakeMessage this way:

...

…where I find this call-site passing a null for clientVersion:

image

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.