summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-04-22 15:28:47 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-04-22 15:28:48 -0700
commitd5fa369bd73d4098c59b3d9949a67f89910e71f1 (patch)
tree40e746fcb373fcc2007f9db5742c4a207a3bcbfa
parentba7f9828eed11ae2e6f50efc57bb79dc07e814e0 (diff)
parent733642b27de051f9fabcd689d160282971a30cef (diff)
downloadlibcore-d5fa369bd73d4098c59b3d9949a67f89910e71f1.zip
libcore-d5fa369bd73d4098c59b3d9949a67f89910e71f1.tar.gz
libcore-d5fa369bd73d4098c59b3d9949a67f89910e71f1.tar.bz2
Merge "Fixing java.lang.NullPointerException at java.net.URI$Helper.isValidDomainName" into dalvik-dev
-rw-r--r--luni/src/main/java/java/net/URI.java14
-rw-r--r--luni/src/test/java/java/net/AllTests.java7
-rw-r--r--luni/src/test/java/java/net/UriTest.java29
3 files changed, 42 insertions, 8 deletions
diff --git a/luni/src/main/java/java/net/URI.java b/luni/src/main/java/java/net/URI.java
index 85c16eb..36637c6 100644
--- a/luni/src/main/java/java/net/URI.java
+++ b/luni/src/main/java/java/net/URI.java
@@ -619,17 +619,21 @@ public final class URI implements Comparable<URI>, Serializable {
return false;
}
- String label = null;
+ String lastLabel = null;
StringTokenizer st = new StringTokenizer(host, "."); //$NON-NLS-1$
while (st.hasMoreTokens()) {
- label = st.nextToken();
- if (label.startsWith("-") || label.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$
+ lastLabel = st.nextToken();
+ if (lastLabel.startsWith("-") || lastLabel.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
}
- if (!label.equals(host)) {
- char ch = label.charAt(0);
+ if (lastLabel == null) {
+ return false;
+ }
+
+ if (!lastLabel.equals(host)) {
+ char ch = lastLabel.charAt(0);
if (ch >= '0' && ch <= '9') {
return false;
}
diff --git a/luni/src/test/java/java/net/AllTests.java b/luni/src/test/java/java/net/AllTests.java
index dbfb3e4..226e2c3 100644
--- a/luni/src/test/java/java/net/AllTests.java
+++ b/luni/src/test/java/java/net/AllTests.java
@@ -22,9 +22,10 @@ import junit.framework.TestSuite;
public class AllTests {
public static final Test suite() {
TestSuite suite = new TestSuite();
- suite.addTestSuite(java.net.IDNTest.class);
- suite.addTestSuite(java.net.SocketTest.class);
- suite.addTestSuite(java.net.URLConnectionTest.class);
+ suite.addTestSuite(IDNTest.class);
+ suite.addTestSuite(SocketTest.class);
+ suite.addTestSuite(URLConnectionTest.class);
+ suite.addTestSuite(UriTest.class);
return suite;
}
}
diff --git a/luni/src/test/java/java/net/UriTest.java b/luni/src/test/java/java/net/UriTest.java
new file mode 100644
index 0000000..9900d5e
--- /dev/null
+++ b/luni/src/test/java/java/net/UriTest.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * 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 java.net;
+
+import junit.framework.TestCase;
+
+public class UriTest extends TestCase {
+
+ /**
+ * Regression test for http://b/issue?id=2604061
+ */
+ public void testParsingDotAsHostname() throws URISyntaxException {
+ assertEquals(null, new URI("http://./").getHost());
+ }
+}