Back to all reviewers

explicit null checks

bazelbuild/bazel
Based on 3 comments
Other

Use explicit null/undefined checks instead of methods that silently handle missing values. When you expect a value to be present, use access patterns that will fail fast if the value is missing rather than returning default values or silently continuing.

Null Handling Other

Reviewer Prompt

Use explicit null/undefined checks instead of methods that silently handle missing values. When you expect a value to be present, use access patterns that will fail fast if the value is missing rather than returning default values or silently continuing.

Prefer explicit checks that fail on missing values:

  • Use dictionary [key] instead of get(key) when the key must be present
  • Use != None instead of truthy checks when distinguishing null from empty collections
  • Add bounds checking before accessing array/string elements

Example from code review:

# Instead of using .get() which silently returns None:
ddi_file = source_to_ddi_file_map.get(source_artifact)

# Use direct access that fails if key is missing:
ddi_file = source_to_ddi_file_map[source_artifact]

# For collections, distinguish None from empty:
if lib.pic_objects != None:  # Not just: if lib.pic_objects:
    # Handle non-null collection (may be empty)

This approach makes your code more robust by catching bugs early when values are unexpectedly missing, rather than allowing silent failures that can be harder to debug later.

3
Comments Analyzed
Other
Primary Language
Null Handling
Category

Source Discussions