James Clampffer created HDFS-10241:
--------------------------------------

             Summary: libhdfs++: Objects should never return mutable references 
to internal state
                 Key: HDFS-10241
                 URL: https://issues.apache.org/jira/browse/HDFS-10241
             Project: Hadoop HDFS
          Issue Type: Sub-task
            Reporter: James Clampffer


Returning mutable references to internal state is always a bad idea.  It's 
particularly bad in asynchronous code (due to unpredictable object life cycles).

Example of what should _never_ happen in production code (from 
AsyncRequestBlock):
{code}
  struct State {
      std::string header;
      hadoop::hdfs::OpReadBlockProto request;
      hadoop::hdfs::BlockOpResponseProto response;
    };
  
    auto m = continuation::Pipeline<State>::Create(cancel_state_);
    State *s = &m->state();
  
    s->header.insert(s->header.begin(),
                     {0, kDataTransferVersion, Operation::kReadBlock});
{code}

I'll open another JIRA for auto vars containing ambiguous types e.g. what is 
the type of "m" here?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to