Return-Path: Delivered-To: apmail-hadoop-zookeeper-commits-archive@locus.apache.org Received: (qmail 47747 invoked from network); 26 Jan 2009 19:22:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Jan 2009 19:22:03 -0000 Received: (qmail 54550 invoked by uid 500); 26 Jan 2009 19:22:03 -0000 Delivered-To: apmail-hadoop-zookeeper-commits-archive@hadoop.apache.org Received: (qmail 54523 invoked by uid 500); 26 Jan 2009 19:22:03 -0000 Mailing-List: contact zookeeper-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: zookeeper-dev@ Delivered-To: mailing list zookeeper-commits@hadoop.apache.org Received: (qmail 54512 invoked by uid 99); 26 Jan 2009 19:22:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Jan 2009 11:22:03 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Jan 2009 19:22:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7CB6E2388A10; Mon, 26 Jan 2009 19:21:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r737784 - in /hadoop/zookeeper/trunk: CHANGES.txt src/java/main/org/apache/jute/Utils.java src/java/test/org/apache/zookeeper/server/ToStringTest.java Date: Mon, 26 Jan 2009 19:21:39 -0000 To: zookeeper-commits@hadoop.apache.org From: mahadev@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090126192139.7CB6E2388A10@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mahadev Date: Mon Jan 26 19:21:38 2009 New Revision: 737784 URL: http://svn.apache.org/viewvc?rev=737784&view=rev Log: ZOOKEEPER-268. tostring on jute generated objects can cause NPE. (pat via mahadev) Added: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ToStringTest.java Modified: hadoop/zookeeper/trunk/CHANGES.txt hadoop/zookeeper/trunk/src/java/main/org/apache/jute/Utils.java Modified: hadoop/zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=737784&r1=737783&r2=737784&view=diff ============================================================================== --- hadoop/zookeeper/trunk/CHANGES.txt (original) +++ hadoop/zookeeper/trunk/CHANGES.txt Mon Jan 26 19:21:38 2009 @@ -68,6 +68,9 @@ ZOOKEEPER-273. Zookeeper c client build should not depend on CPPUNIT. (pat and runping via mahadev) + + ZOOKEEPER-268. tostring on jute generated objects can cause NPE. (pat via +mahadev) IMPROVEMENTS: Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/Utils.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/Utils.java?rev=737784&r1=737783&r2=737784&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/Utils.java (original) +++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/Utils.java Mon Jan 26 19:21:38 2009 @@ -19,20 +19,17 @@ package org.apache.jute; import java.io.ByteArrayOutputStream; -import java.io.DataInput; -import java.io.DataOutput; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.charset.CharacterCodingException; /** - * Various utility functions for Hadooop record I/O runtime. + * Various utility functions for Hadoop record I/O runtime. * @author Milind Bhandarkar */ public class Utils { /** Cannot create a new instance of Utils */ private Utils() { + super(); } /** @@ -56,7 +53,7 @@ return true; } - public static final char[] hexchars = { '0', '1', '2', '3', '4', '5', + private static final char[] hexchars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** @@ -64,8 +61,10 @@ * @param s * @return */ - static String toXMLString(String t) { - String s = t.toString(); + static String toXMLString(String s) { + if (s == null) + return ""; + StringBuffer sb = new StringBuffer(); for (int idx = 0; idx < s.length(); idx++) { char ch = s.charAt(idx); @@ -197,9 +196,12 @@ * @return */ static String toXMLBuffer(byte barr[]) { + if (barr == null || barr.length == 0) { + return ""; + } StringBuffer sb = new StringBuffer(2*barr.length); for (int idx = 0; idx < barr.length; idx++) { - sb.append(Integer.toHexString((int)barr[idx])); + sb.append(Integer.toHexString(barr[idx])); } return sb.toString(); } @@ -231,10 +233,13 @@ * @return */ static String toCSVBuffer(byte barr[]) { - StringBuffer sb = new StringBuffer(barr.length+1); + if (barr == null || barr.length == 0) { + return ""; + } + StringBuffer sb = new StringBuffer(barr.length + 1); sb.append('#'); for(int idx = 0; idx < barr.length; idx++) { - sb.append(Integer.toHexString((int)barr[idx])); + sb.append(Integer.toHexString(barr[idx])); } return sb.toString(); } Added: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ToStringTest.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ToStringTest.java?rev=737784&view=auto ============================================================================== --- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ToStringTest.java (added) +++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ToStringTest.java Mon Jan 26 19:21:38 2009 @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.zookeeper.server; + +import junit.framework.TestCase; + +import org.apache.zookeeper.proto.SetDataRequest; +import org.junit.Test; + +/** + * A misc place to verify toString methods - mainly to make sure they don't + * fail. + */ +public class ToStringTest extends TestCase { + /** Verify jute - which we've had particular problems with in the past + * wrt null fields */ + @Test + public void testJuteToString() { + SetDataRequest req = new SetDataRequest(null, null, 0); + assertNotSame("ERROR", req.toString()); + } +}