protected static boolean isValidValue(Field f, Object value) {
    if (value != null) {
      return true;
    }

    Schema schema = f.schema();
    Type type = schema.getType();

    // If the type is null, any value is valid
    if (type == Type.NULL) {
      return true;
    }

    // If the type is a union that allows nulls, any value is valid
    if (type == Type.UNION) {
      for (Schema s : schema.getTypes()) {
        if (s.getType() == Type.NULL) {
          return true;
        }
      }
    }

    // The value is null but the type does not allow nulls
    return false;
  }
@Test
  void isValidValueWithNullField() {
    // Verify that null is a valid value for null fields:
    assertTrue(RecordBuilderBase.isValidValue(new Field("f", Schema.create(Type.NULL), null, null), null));
  }