[
https://issues.apache.org/jira/browse/AVRO-1680?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sean Busbey updated AVRO-1680:
------------------------------
Labels: beginner (was: )
> 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: doc, java
> Affects Versions: 1.7.7
> Reporter: Eugene Kirpichov
> Priority: Trivial
> Labels: beginner
>
> 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.4.14#64029)