You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/01/05 11:09:58 UTC

svn commit: r492957 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/DatagramSocket.java main/java/org/apache/harmony/luni/util/ExternalMessages.properties test/java/tests/api/java/net/DatagramSocketTest.java

Author: tellison
Date: Fri Jan  5 02:09:57 2007
New Revision: 492957

URL: http://svn.apache.org/viewvc?view=rev&rev=492957
Log:
Apply slightly modified patch for HARMONY-2938 ([classlib][luni]no NPE was thrown when send a DatagramPacket with no dest addresss)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocket.java?view=diff&rev=492957&r1=492956&r2=492957
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocket.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocket.java Fri Jan  5 02:09:57 2007
@@ -406,10 +406,14 @@
 				pack.setPort(port);
 			}
 		} else {
-			// not connected so the target address cannot be null
-			if (packAddr == null) {
-				return;
-			}
+			// not connected so the target address is not allowed to be null
+            if (packAddr == null) {
+                if (pack.port == -1) {
+                    // KA019 Destination address is null
+                    throw new NullPointerException(Msg.getString("KA019")); //$NON-NLS-1$
+                }
+                return;
+            }
 			SecurityManager security = System.getSecurityManager();
 			if (security != null) {
 				if (packAddr.isMulticastAddress())

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties?view=diff&rev=492957&r1=492956&r2=492957
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties Fri Jan  5 02:09:57 2007
@@ -311,3 +311,4 @@
 KA016=Received authentication challenge is null
 KA017=Received HTTP_PROXY_AUTH (407) code while not using proxy
 KA018=Received authentication challenge is null
+KA019=Destination address is null

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java?view=diff&rev=492957&r1=492956&r2=492957
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/DatagramSocketTest.java Fri Jan  5 02:09:57 2007
@@ -961,6 +961,18 @@
         InetSocketAddress sa = InetSocketAddress.createUnresolved("localhost", 0); 
         //no exception expected for next line
         new testDatagramSocket(new testDatagramSocketImpl()).send(new DatagramPacket(new byte[272], 3, sa)); 
+        
+        // Regression test for Harmony-2938
+        InetAddress i = InetAddress.getByName("127.0.0.1");
+        DatagramSocket d = new DatagramSocket(80, i);
+        try {
+            d.send(new DatagramPacket(new byte[] { 1 }, 1));
+            fail("should throw NPE.");
+        } catch (NullPointerException e) {
+            // expected;
+        } finally {
+            d.close();
+        }
 	}
 
 	/**