harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r375338 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/InetAddress.java test/java/org/apache/harmony/tests/java/net/AllTests.java test/java/org/apache/harmony/tests/java/net/InetAddressTest.java
Date Mon, 06 Feb 2006 19:22:35 GMT
Author: tellison
Date: Mon Feb  6 11:22:32 2006
New Revision: 375338

URL: http://svn.apache.org/viewcvs?rev=375338&view=rev
Log:
Fix for HARMONY-61 (java.net.InetAddress.getByAddress(null) throws NPE instead of UnknownHostException)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java?rev=375338&r1=375337&r2=375338&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
Mon Feb  6 11:22:32 2006
@@ -743,7 +743,7 @@
 	static InetAddress getByAddress(byte[] ipAddress, int scope_id)
 			throws UnknownHostException {
 		byte[] copy_address;
-		if (ipAddress.length == 4) {
+		if (ipAddress != null && ipAddress.length == 4) {
 			copy_address = new byte[4];
 			for (int i = 0; i < 4; i++) {
 				copy_address[i] = ipAddress[i];
@@ -751,7 +751,7 @@
 			return new Inet4Address(ipAddress);
 		}
 
-		if (ipAddress.length == 16) {
+		if (ipAddress != null && ipAddress.length == 16) {
 			// First check to see if the address is an IPv6-mapped
 			// IPv4 address. If it is, then we can make it a IPv4
 			// address, otherwise, we'll create an IPv6 address.
@@ -837,7 +837,7 @@
 	static InetAddress getByAddress(String hostName, byte[] ipAddress,
 			int scope_id) throws UnknownHostException {
 		byte[] copy_address;
-		if (ipAddress.length == 4) {
+		if (ipAddress != null && ipAddress.length == 4) {
 			copy_address = new byte[4];
 			for (int i = 0; i < 4; i++) {
 				copy_address[i] = ipAddress[i];
@@ -845,7 +845,7 @@
 			return new Inet4Address(ipAddress, hostName);
 		}
 
-		if (ipAddress.length == 16) {
+		if (ipAddress != null && ipAddress.length == 16) {
 			// First check to see if the address is an IPv6-mapped
 			// IPv4 address. If it is, then we can make it a IPv4
 			// address, otherwise, we'll create an IPv6 address.
@@ -864,6 +864,7 @@
 
 			return new Inet6Address(ipAddress, hostName, scope_id);
 		}
+
 		throw new UnknownHostException(Msg.getString("K0332", hostName));
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java?rev=375338&r1=375337&r2=375338&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java
Mon Feb  6 11:22:32 2006
@@ -28,8 +28,9 @@
 		TestSuite suite = new TestSuite(
 				"Test for org.apache.harmony.tests.java.net");
 		//$JUnit-BEGIN$
-		suite.addTestSuite(URITest.class);
 		suite.addTestSuite(URLEncoderTest.class);
+		suite.addTestSuite(InetAddressTest.class);
+		suite.addTestSuite(URITest.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java?rev=375338&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/InetAddressTest.java
Mon Feb  6 11:22:32 2006
@@ -0,0 +1,37 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.tests.java.net;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import junit.framework.TestCase;
+
+public class InetAddressTest extends TestCase {
+
+	/**
+	 * @tests java.net.InetAddress#getByAddress(byte[])
+	 */
+	public void test_getByAddress() {
+		// Regression for HARMONY-61
+		try {
+			InetAddress.getByAddress(null);
+			fail("Assert 0: UnknownHostException must be thrown");
+		} catch (UnknownHostException e) {
+			// Expected
+		}
+	}
+}



Mime
View raw message