Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 769CB172C8 for ; Tue, 9 Jun 2015 20:56:02 +0000 (UTC) Received: (qmail 471 invoked by uid 500); 9 Jun 2015 20:56:01 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 400 invoked by uid 500); 9 Jun 2015 20:56:01 -0000 Mailing-List: contact dev-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list dev@avro.apache.org Received: (qmail 226 invoked by uid 99); 9 Jun 2015 20:56:01 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Jun 2015 20:56:01 +0000 Date: Tue, 9 Jun 2015 20:56:01 +0000 (UTC) From: "Eugene Kirpichov (JIRA)" To: dev@avro.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (AVRO-1680) Problems with code snippet in Decoder#readMapStart javadocs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 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)