Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 38108 invoked from network); 24 Apr 2009 02:53:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Apr 2009 02:53:53 -0000 Received: (qmail 15598 invoked by uid 500); 24 Apr 2009 02:53:53 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 15528 invoked by uid 500); 24 Apr 2009 02:53:53 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 15519 invoked by uid 99); 24 Apr 2009 02:53:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Apr 2009 02:53:53 +0000 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; Fri, 24 Apr 2009 02:53:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 300FF2388A36; Fri, 24 Apr 2009 02:53:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r768133 - in /harmony/enhanced/classlib/trunk/modules/lang-management/src: main/java/java/lang/management/ test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/ Date: Fri, 24 Apr 2009 02:53:31 -0000 To: commits@harmony.apache.org From: ndbeyer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090424025332.300FF2388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ndbeyer Date: Fri Apr 24 02:53:31 2009 New Revision: 768133 URL: http://svn.apache.org/viewvc?rev=768133&view=rev Log: Apply modified patch for HARMONY-6148 - [classlib][lang-management] java.lang.management.MemoryNotificationInfo.from(CompositeData cd) should return null if the argument is null Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java?rev=768133&r1=768132&r2=768133&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java (original) +++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java Fri Apr 24 02:53:31 2009 @@ -37,11 +37,14 @@ *

* * @param cd The CompositeDate object to retrieve data from. - * @return A MemoryNotificationInfo instance. + * @return A MemoryNotificationInfo instance or {@code null} if {@code cd} is {@code null} * @throws IllegalArgumentException if cd does not contain * MemoryUsage data. */ public static MemoryNotificationInfo from(CompositeData cd) { + if (cd == null) { + return null; + } String poolName = (String) cd.get("poolName"); MemoryUsage usage = MemoryUsage.from((CompositeData) cd.get("usage")); long count = ((Long) cd.get("count")).longValue(); @@ -62,9 +65,19 @@ * @param poolName The memory pool name. * @param usage The memory usage snapshot. * @param count The threshold crossing count. + * + * @throws NullPointerException if {@code poolName} or {@code usage} is {@code null} */ public MemoryNotificationInfo(String poolName, MemoryUsage usage, long count) { super(); + if (poolName == null) { + throw new NullPointerException("pooName is null"); //$NON-NLS-1$ + } + + if (usage == null) { + throw new NullPointerException("usage is null"); //$NON-NLS-1$ + } + this.poolName = poolName; this.usage = usage; this.count = count; Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java?rev=768133&r1=768132&r2=768133&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java (original) +++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryUsage.java Fri Apr 24 02:53:31 2009 @@ -39,6 +39,9 @@ * MemoryUsage data. */ public static MemoryUsage from(CompositeData cd) { + if (cd == null) { + return null; + } try { long init = ((Long) cd.get("init")).longValue(); long used = ((Long) cd.get("used")).longValue(); Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java?rev=768133&view=auto ============================================================================== --- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java (added) +++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryNotificationInfoTest.java Fri Apr 24 02:53:31 2009 @@ -0,0 +1,90 @@ +/* + * 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.harmony.lang.management.tests.java.lang.management; + +import java.lang.management.MemoryNotificationInfo; +import java.lang.management.MemoryUsage; + +import javax.management.openmbean.CompositeData; + +import junit.framework.TestCase; + +import org.apache.harmony.lang.management.ManagementUtils; + +public class MemoryNotificationInfoTest extends TestCase { + + public void test_Constructor_NullPoolName_NullUsage() { + try { + new MemoryNotificationInfo((String) null, (MemoryUsage) null, + -4294901761L); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + } + + public void test_Constructor_NullUsage() { + try { + new MemoryNotificationInfo("poolName", (MemoryUsage) null, + -4294901761L); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // Expected + } + } + + public void test_from_NullCompositeData() { + assertNull(MemoryNotificationInfo.from(null)); + } + + public void test_from() { + final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4); + final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42); + + CompositeData compositeData = ManagementUtils + .toMemoryNotificationInfoCompositeData(memoryNotifyInfo); + MemoryNotificationInfo fromInfo = MemoryNotificationInfo + .from(compositeData); + assertEquals(memoryNotifyInfo.getPoolName(), fromInfo.getPoolName()); + assertEquals(memoryNotifyInfo.getCount(), fromInfo.getCount()); + + MemoryUsage fromUsage = fromInfo.getUsage(); + assertEquals(memoryUsage.getInit(), fromUsage.getInit()); + assertEquals(memoryUsage.getMax(), fromUsage.getMax()); + assertEquals(memoryUsage.getUsed(), fromUsage.getUsed()); + assertEquals(memoryUsage.getCommitted(), fromUsage.getCommitted()); + } + + public void test_getPoolName() { + final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4); + final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42); + assertEquals("Lloyd", memoryNotifyInfo.getPoolName()); + } + + public void test_getUsage() { + final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4); + final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42); + assertEquals(memoryUsage, memoryNotifyInfo.getUsage()); + } + + public void test_get() { + final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4); + final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42); + assertEquals(42, memoryNotifyInfo.getCount()); + } +} Modified: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java?rev=768133&r1=768132&r2=768133&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/MemoryUsageTest.java Fri Apr 24 02:53:31 2009 @@ -90,6 +90,10 @@ } } + public void test_from_NullCompositeData() { + assertNull(MemoryUsage.from(null)); + } + public void testConstructor() { try { new MemoryUsage(-2, 2048, 4096, 8128);