Merge "Move some libcore test modules to soong"
am: 5525ce2101

Change-Id: I4838d6c29331999de35193c88523bdc14be7baa2
diff --git a/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java b/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java
index 5a84c8e..87c3096 100644
--- a/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java
+++ b/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java
@@ -87,7 +87,7 @@
         // Hardcode MessagePattern apostrophe mode to be default. b/27265238
         { "android.icu.text.MessagePattern.ApostropheMode", null },
 
-        // Hardcode "sun.io.useCanonCaches" to use the default (on). b/28174137
+        // Hardcode "sun.io.useCanonCaches" to use the default (off). b/28174137, b/62301183
         { "sun.io.useCanonCaches", null },
         { "sun.io.useCanonPrefixCache", null },
 
@@ -111,4 +111,3 @@
         { "java.util.logging.manager", null },
     };
 }
-
diff --git a/luni/src/test/java/libcore/java/io/FileTest.java b/luni/src/test/java/libcore/java/io/FileTest.java
index 9226e02..3705f2b 100644
--- a/luni/src/test/java/libcore/java/io/FileTest.java
+++ b/luni/src/test/java/libcore/java/io/FileTest.java
@@ -393,4 +393,25 @@
             fail();
         } catch (InvalidPathException expected) {}
     }
+
+    // http://b/62301183
+    public void test_canonicalCachesAreOff() throws Exception {
+        File tempDir = createTemporaryDirectory();
+        File f1 = new File(tempDir, "testCannonCachesOff1");
+        f1.createNewFile();
+        File f2  = new File(tempDir, "testCannonCachesOff2");
+        f2.createNewFile();
+        File symlinkFile = new File(tempDir, "symlink");
+
+        // Create a symlink from symlink to f1 and populate canonical path cache
+        assertEquals(0, Runtime.getRuntime().exec("ln -s " + f1.getAbsolutePath() + " " + symlinkFile.getAbsolutePath()).waitFor());
+        assertEquals(symlinkFile.getCanonicalPath(), f1.getCanonicalPath());
+
+        // Remove it and replace it with a symlink to f2 (using java File/Files would flush caches).
+        assertEquals(0, Runtime.getRuntime().exec("rm " + symlinkFile.getAbsolutePath()).waitFor());
+        assertEquals(0, Runtime.getRuntime().exec("ln -s " + f2.getAbsolutePath() + " " + symlinkFile.getAbsolutePath()).waitFor());
+
+        // Did we cache canonical path results? hope not!
+        assertEquals(symlinkFile.getCanonicalPath(), f2.getCanonicalPath());
+    }
 }
diff --git a/luni/src/test/java/libcore/java/net/FtpURLConnectionTest.java b/luni/src/test/java/libcore/java/net/FtpURLConnectionTest.java
index 2842a0a..74948f6 100644
--- a/luni/src/test/java/libcore/java/net/FtpURLConnectionTest.java
+++ b/luni/src/test/java/libcore/java/net/FtpURLConnectionTest.java
@@ -44,15 +44,11 @@
 import java.util.Locale;
 import java.util.Objects;
 import java.util.Random;
-import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
- import sun.net.ftp.FtpLoginException;
+import sun.net.ftp.FtpLoginException;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
@@ -253,6 +249,34 @@
         }
     }
 
+    // http://b/35784677
+    public void testCRLFInUserinfo() throws Exception {
+        int serverPort = fakeFtpServer.getServerControlPort();
+        List<String> encodedUserInfos = Arrays.asList(
+                // '\r\n' in the username with password
+                "user%0D%0Acommand:password",
+                // '\r\n' in the password
+                "user:password%0D%0Acommand",
+                // just '\n' in the password
+                "user:password%0Acommand",
+                // just '\n' in the username
+                "user%0Acommand:password"
+        );
+        for (String encodedUserInfo : encodedUserInfos) {
+            String urlString = String.format(Locale.US, "ftp://%s@%s:%s/%s",
+                    encodedUserInfo, SERVER_HOSTNAME, serverPort, FILE_PATH);
+            try {
+                new URL(urlString).openConnection().connect();
+                fail("Connection shouldn't have succeeded: " + urlString);
+            } catch (FtpLoginException expected) {
+                // The original message "Illegal carriage return" gets lost
+                // where FtpURLConnection.connect() translates the
+                // original FtpProtocolException into FtpLoginException.
+                assertEquals("Invalid username/password", expected.getMessage());
+            }
+        }
+    }
+
     private InputStream openFileSystemContents(String fileName) throws IOException {
         String fullFileName = VALID_USER_HOME_DIR + "/" + fileName;
         FileEntry entry = (FileEntry) fileSystem.getEntry(fullFileName);
@@ -279,49 +303,6 @@
         }
     }
 
-    // http://b/35784677
-    public void testCRLFInUserinfo() throws Exception {
-        List<String> encodedUserInfos = Arrays.asList(
-                // '\r\n' in the username with password
-                "user%0D%0Acommand:password",
-                // '\r\n' in the password
-                "user:password%0D%0Acommand",
-                // just '\n' in the password
-                "user:password%0Acommand",
-                // just '\n' in the username
-                "user%0Acommand:password"
-        );
-        for (String encodedUserInfo : encodedUserInfos) {
-            ExecutorService executor = Executors.newSingleThreadExecutor();
-            ServerSocket mockFtpServerSocket = new ServerSocket(0);
-            Future<Void> future = executor.submit(new Callable<Void>() {
-                @Override public Void call() throws Exception {
-                    Socket clientSocket = mockFtpServerSocket.accept();
-                    clientSocket.getOutputStream().write("220 o/".getBytes());
-                    clientSocket.close();
-                    return null;
-                }
-              });
-            executor.shutdown();
-
-            String urlString = String.format(Locale.US, "ftp://%s@%s:%s/%s",
-                    encodedUserInfo, SERVER_HOSTNAME, mockFtpServerSocket.getLocalPort(), FILE_PATH);
-            try {
-                new URL(urlString).openConnection().connect();
-                fail("Connection shouldn't have succeeded: " + urlString);
-            } catch (FtpLoginException expected) {
-                // The original message "Illegal carriage return" gets lost
-                // where FtpURLConnection.connect() translates the
-                // original FtpProtocolException into FtpLoginException.
-                assertEquals("Invalid username/password", expected.getMessage());
-            }
-
-            // Cleanup
-            future.get();
-            mockFtpServerSocket.close();
-        }
-    }
-
     private URL getFileUrlWithCredentials(String user, String password, String filePath) {
         Objects.requireNonNull(user);
         Objects.requireNonNull(filePath);
diff --git a/ojluni/src/main/java/java/io/FileSystem.java b/ojluni/src/main/java/java/io/FileSystem.java
index 4b0260d..86d8fff 100644
--- a/ojluni/src/main/java/java/io/FileSystem.java
+++ b/ojluni/src/main/java/java/io/FileSystem.java
@@ -226,8 +226,11 @@
 
     // Flags for enabling/disabling performance optimizations for file
     // name canonicalization
-    static boolean useCanonCaches      = true;
-    static boolean useCanonPrefixCache = true;
+    // Android-changed: Disabled caches for security reasons (b/62301183)
+    //static boolean useCanonCaches      = true;
+    //static boolean useCanonPrefixCache = true;
+    static boolean useCanonCaches      = false;
+    static boolean useCanonPrefixCache = false;
 
     private static boolean getBooleanProperty(String prop, boolean defaultVal) {
         String val = System.getProperty(prop);
diff --git a/ojluni/src/main/java/javax/net/ssl/SSLSocketFactory.java b/ojluni/src/main/java/javax/net/ssl/SSLSocketFactory.java
index d6c3f76..93b5dc7 100644
--- a/ojluni/src/main/java/javax/net/ssl/SSLSocketFactory.java
+++ b/ojluni/src/main/java/javax/net/ssl/SSLSocketFactory.java
@@ -260,6 +260,8 @@
      * @throws NullPointerException if {@code s} is {@code null}
      *
      * @since 1.8
+     *
+     * @hide
      */
     public Socket createSocket(Socket s, InputStream consumed,
             boolean autoClose) throws IOException {
diff --git a/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java b/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java
index 9526d3b..0c117d4 100644
--- a/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java
+++ b/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it