Return-Path: X-Original-To: apmail-pig-dev-archive@www.apache.org Delivered-To: apmail-pig-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 037803438 for ; Sat, 7 May 2011 01:13:43 +0000 (UTC) Received: (qmail 91763 invoked by uid 500); 7 May 2011 01:13:42 -0000 Delivered-To: apmail-pig-dev-archive@pig.apache.org Received: (qmail 91734 invoked by uid 500); 7 May 2011 01:13:42 -0000 Mailing-List: contact dev-help@pig.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pig.apache.org Delivered-To: mailing list dev@pig.apache.org Received: (qmail 91726 invoked by uid 500); 7 May 2011 01:13:42 -0000 Delivered-To: apmail-hadoop-pig-dev@hadoop.apache.org Received: (qmail 91723 invoked by uid 99); 7 May 2011 01:13:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 01:13:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 01:13:41 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 235D7C468C for ; Sat, 7 May 2011 01:13:03 +0000 (UTC) Date: Sat, 7 May 2011 01:13:03 +0000 (UTC) From: "Daniel Dai (JIRA)" To: pig-dev@hadoop.apache.org Message-ID: <1367255362.29651.1304730783141.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <11100989.199961295987624679.JavaMail.jira@thor> Subject: [jira] [Commented] (PIG-1821) UDFContext.getUDFProperties does not handle collisions in hashcode of udf classname (+ arg hashcodes) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PIG-1821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13030243#comment-13030243 ] Daniel Dai commented on PIG-1821: --------------------------------- +1 > UDFContext.getUDFProperties does not handle collisions in hashcode of udf classname (+ arg hashcodes) > ----------------------------------------------------------------------------------------------------- > > Key: PIG-1821 > URL: https://issues.apache.org/jira/browse/PIG-1821 > Project: Pig > Issue Type: Bug > Affects Versions: 0.8.0 > Reporter: Thejas M Nair > Assignee: Thejas M Nair > Fix For: 0.9.0 > > Attachments: PIG-1821.1.patch, PIG-1821.2.patch, PIG-1821.3.patch > > > In code below, if generateKey() returns same value for two udfs, the udfs would end up sharing the properties object. > {code} > private HashMap udfConfs = new HashMap(); > public Properties getUDFProperties(Class c) { > Integer k = generateKey(c); > Properties p = udfConfs.get(k); > if (p == null) { > p = new Properties(); > udfConfs.put(k, p); > } > return p; > } > private int generateKey(Class c) { > return c.getName().hashCode(); > } > public Properties getUDFProperties(Class c, String[] args) { > Integer k = generateKey(c, args); > Properties p = udfConfs.get(k); > if (p == null) { > p = new Properties(); > udfConfs.put(k, p); > } > return p; > } > private int generateKey(Class c, String[] args) { > int hc = c.getName().hashCode(); > for (int i = 0; i < args.length; i++) { > hc <<= 1; > hc ^= args[i].hashCode(); > } > return hc; > } > {code} > To prevent this, a new class (say X) that can hold the classname and args should be created, and instead of HashMap, HashMap should be used. Then HahsMap will deal with the collisions. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira