Merge "Update java.beans to openJdk8u121"
am: 8889b950ab

Change-Id: I56e8c268740c479e82f573c001b1cbb57293b65c
diff --git a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java
index c199bca..b85f69a 100644
--- a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java
@@ -264,6 +264,11 @@
                 assertEquals(0, Libcore.os.lseek(fis.getFD(), 0, OsConstants.SEEK_CUR));
                 assertEquals(lastByte, fis.skip(lastByte));
             }
+
+            FileInputStream fis = new FileInputStream(largeFile);
+            long lastByte = 3 * 1024 * 1024 * 1024L - 1;
+            assertEquals(0, Libcore.os.lseek(fis.getFD(), 0, OsConstants.SEEK_CUR));
+            assertEquals(lastByte, fis.skip(lastByte));
         } finally {
             // Proactively cleanup - it's a pretty large file.
             assertTrue(largeFile.delete());
diff --git a/luni/src/test/java/libcore/java/net/URLTest.java b/luni/src/test/java/libcore/java/net/URLTest.java
index 3a14063..231e09c 100644
--- a/luni/src/test/java/libcore/java/net/URLTest.java
+++ b/luni/src/test/java/libcore/java/net/URLTest.java
@@ -194,6 +194,14 @@
         assertEquals(null, url.getRef());
     }
 
+    // This behavior of URLs with invalid user info changed due to bug http://b/33351987 after
+    // Android security level 1 April 2017.
+    public void testAtSignInUserInfo() throws Exception {
+        URL url = new URL("http://user@userhost.com:password@host");
+        assertNull(url.getUserInfo());
+        assertTrue(url.getHost().isEmpty());
+    }
+
     public void testUserNoPassword() throws Exception {
         URL url = new URL("http://user@host");
         assertEquals("user@host", url.getAuthority());
@@ -755,6 +763,28 @@
         assertEquals("/some/path", new URL("http://foobar.com/some/path?#").getFile());
     }
 
+    // http://b/31858037
+    public void testFragmentWithSlash() throws Exception {
+        final String host = "example.com";
+        final String fragment = "@not-a-host-name/a";
+        URL url = new URL(String.format("http://%s#%s", host, fragment));
+        assertNull(url.getUserInfo());
+        assertEquals(host, url.getAuthority());
+        assertEquals(host, url.getHost());
+        assertEquals(fragment, url.getRef());
+    }
+
+    // http://b/31858037
+    public void testFragmentWithQuery() throws Exception {
+        final String host = "example.com";
+        final String fragment = "@not-a-host-name?a";
+        URL url = new URL(String.format("http://%s#%s", host, fragment));
+        assertNull(url.getUserInfo());
+        assertEquals(host, url.getAuthority());
+        assertEquals(host, url.getHost());
+        assertEquals(fragment, url.getRef());
+    }
+
     // http://b/33351987
     public void testMultipleUserField() throws Exception {
         final String host = "http://multiple@users@url.com";
diff --git a/ojluni/src/main/java/java/net/URLStreamHandler.java b/ojluni/src/main/java/java/net/URLStreamHandler.java
index 1521b1b..eac8a78 100644
--- a/ojluni/src/main/java/java/net/URLStreamHandler.java
+++ b/ojluni/src/main/java/java/net/URLStreamHandler.java
@@ -168,9 +168,9 @@
             (spec.charAt(start + 1) == '/')) {
             start += 2;
             i = spec.indexOf('/', start);
-            if (i < 0) {
+            if (i < 0 || i > limit) {
                 i = spec.indexOf('?', start);
-                if (i < 0)
+                if (i < 0 || i > limit)
                     i = limit;
             }
 
@@ -178,8 +178,14 @@
 
             int ind = authority.indexOf('@');
             if (ind != -1) {
-                userInfo = authority.substring(0, ind);
-                host = authority.substring(ind+1);
+                if (ind != authority.lastIndexOf('@')) {
+                    // more than one '@' in authority. This is not server based
+                    userInfo = null;
+                    host = null;
+                } else {
+                    userInfo = authority.substring(0, ind);
+                    host = authority.substring(ind+1);
+                }
             } else {
                 userInfo = null;
             }