You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Eugene Kirpichov (JIRA)" <ji...@apache.org> on 2015/06/09 22:56:01 UTC

[jira] [Created] (AVRO-1680) Problems with code snippet in Decoder#readMapStart javadocs

Eugene Kirpichov created AVRO-1680:
--------------------------------------

             Summary: Problems with code snippet in Decoder#readMapStart javadocs
                 Key: AVRO-1680
                 URL: https://issues.apache.org/jira/browse/AVRO-1680
             Project: Avro
          Issue Type: Improvement
          Components: java
    Affects Versions: 1.7.7
            Reporter: Eugene Kirpichov
            Priority: Trivial


https://github.com/apache/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/Decoder.java javadocs ( http://avro.apache.org/docs/1.7.7/api/java/org/apache/avro/io/Decoder.html#readMapStart() ) say:
{code:java}
    Map m = new HashMap();
    Record reuse = new Record();
    for(long i = in.readMapStart(); i != 0; i = in.readMapNext()) {
      for (long j = 0; j < i; j++) {
        String key = in.readString();
        reuse.intField = in.readInt();
        reuse.boolField = in.readBoolean();
        m.put(key, reuse);
      }
   }
{code}

This can be improved in two ways:
1) Javadoc ate the generic arguments. This can be fixed by wrapping into \{@code}.
2) The mutable record object is being reused; as a result, the map will have the same shared object mapped to every key. I don't think this is likely to be the user's intention, so a new Record should be created on every iteration.

Actually in 3 ways.
3) a much better name for "i" would be "numRecords", because otherwise it seems like "j" and "i" have similar roles (indices over some containers), which they don't - "i" is not an index into any container, only j is. Then "j" can be renamed to "i".



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