Merge "Verify StackTraceElement against OpenJDK 8u121-b13."
diff --git a/AndroidTest-core-tests.xml b/AndroidTest-core-tests.xml
new file mode 100644
index 0000000..8d8f7ae
--- /dev/null
+++ b/AndroidTest-core-tests.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+<!-- This test config is placed here for use by atest to enable it to determine
+ which tests to run for core-tests.jar (only). It assumes that the majority
+ of tests for libcore are in the CtsLibcoreTestCases module and therefore
+ does not help for tests where that is not the case.
+
+ This file is effectively a copy of the real CtsLibcoreTestCases
+ AndroidTest.xml file and should track the content of that file.
+
+ TODO: b/114773808 to remove this copied config and execute core-tests.jar
+ directly.
+-->
+<configuration description="Config for Libcore test cases">
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/java.io.tmpdir" />
+ <option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/user.home" />
+ <option name="teardown-command" value="rm -rf /data/local/tmp/ctslibcore" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <!-- this has just the instrumentation which acts as the tests we want to run -->
+ <option name="test-file-name" value="CtsLibcoreTestCases.apk" />
+ </target_preparer>
+ <test class="com.android.compatibility.testtype.LibcoreTest" >
+ <option name="package" value="android.libcore.cts" />
+ <option name="instrumentation-arg" key="filter"
+ value="com.android.cts.core.runner.ExpectationBasedFilter" />
+ <option name="core-expectation" value="/knownfailures.txt" />
+ <option name="runtime-hint" value="45m"/>
+ <!-- 20x default timeout of 600sec -->
+ <option name="shell-timeout" value="12000000"/>
+ <option name="hidden-api-checks" value="false"/>
+ </test>
+</configuration>
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index 21645d3..00a3edd 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -127,7 +127,6 @@
java_resource_dirs: core_resource_dirs,
java_resources: [":android_icu4j_resources"],
- java_version: "1.9",
required: [
"tzdata",
@@ -193,7 +192,6 @@
srcs: [":core_libart_java_files"],
java_resources: [":android_icu4j_resources"],
- java_version: "1.9",
no_standard_libs: true,
libs: ["core-all"],
@@ -247,7 +245,6 @@
dex_preopt: {
enabled: false,
},
- java_version: "1.9",
notice: "ojluni/NOTICE",
required: [
"tzdata",
@@ -412,6 +409,8 @@
"-Xep:ComparisonOutOfRange:ERROR",
],
},
+
+ test_config: "AndroidTest-core-tests.xml",
}
// Make the core-ojtests library.
@@ -500,7 +499,6 @@
droidstubs {
name: "core-current-stubs-gen",
srcs: [":core_api_files"],
- java_version: "1.9",
installable: false,
no_framework_libs: true,
args: " --exclude-annotations",
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java
index f8d2847..930fa3f 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLEngineTest.java
@@ -25,8 +25,10 @@
import java.nio.channels.Pipe.SourceChannel;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
@@ -62,7 +64,10 @@
assertEquals(-1, e.getPeerPort());
String[] suites = e.getSupportedCipherSuites();
e.setEnabledCipherSuites(suites);
- assertEquals(e.getEnabledCipherSuites().length, suites.length);
+ // By default, the engine only supports TLS 1.2, so the TLS 1.3 cipher suites
+ // shouldn't be enabled.
+ assertEquals(suites.length - StandardNames.CIPHER_SUITES_TLS13.size(),
+ e.getEnabledCipherSuites().length);
}
/**
@@ -99,7 +104,10 @@
assertEquals(e.getPeerPort(), port);
String[] suites = e.getSupportedCipherSuites();
e.setEnabledCipherSuites(suites);
- assertEquals(e.getEnabledCipherSuites().length, suites.length);
+ // By default, the engine only supports TLS 1.2, so the TLS 1.3 cipher suites
+ // shouldn't be enabled.
+ assertEquals(suites.length - StandardNames.CIPHER_SUITES_TLS13.size(),
+ e.getEnabledCipherSuites().length);
e.setUseClientMode(true);
assertTrue(e.getUseClientMode());
}
@@ -176,8 +184,12 @@
sse.setEnabledCipherSuites(st);
String[] res = sse.getEnabledCipherSuites();
assertNotNull("Null array was returned", res);
- assertEquals("Incorrect array length", res.length, st.length);
- assertTrue("Incorrect array was returned", Arrays.equals(res, st));
+ // By default, the engine only supports TLS 1.2, so the TLS 1.3 cipher suites
+ // shouldn't be enabled.
+ List<String> supported = new ArrayList<>(Arrays.asList(st));
+ supported.removeAll(StandardNames.CIPHER_SUITES_TLS13);
+ assertEquals("Incorrect array length", res.length, supported.size());
+ assertEquals("Incorrect array was returned", Arrays.asList(res), supported);
try {
sse.setEnabledCipherSuites(null);
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java
index 117a1a0..247b4e4 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLServerSocketTest.java
@@ -16,6 +16,8 @@
package org.apache.harmony.tests.javax.net.ssl;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.TestCase;
import java.io.ByteArrayInputStream;
@@ -31,6 +33,7 @@
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
+import libcore.java.security.StandardNames;
public class SSLServerSocketTest extends TestCase {
@@ -226,8 +229,12 @@
sss.setEnabledCipherSuites(sss.getSupportedCipherSuites());
String[] res = sss.getEnabledCipherSuites();
assertNotNull("NULL result", res);
+ // By default, the socket only supports TLS 1.2, so the TLS 1.3 cipher suites
+ // shouldn't be enabled.
+ List<String> supported = new ArrayList<>(Arrays.asList(sss.getSupportedCipherSuites()));
+ supported.removeAll(StandardNames.CIPHER_SUITES_TLS13);
assertEquals("not all supported cipher suites were enabled",
- Arrays.asList(sss.getSupportedCipherSuites()),
+ supported,
Arrays.asList(res));
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java
index 5712a48..d30ae53a 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/javax/net/ssl/SSLSocketTest.java
@@ -23,8 +23,10 @@
import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.SecureRandom;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
+import java.util.List;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.KeyManager;
@@ -371,8 +373,12 @@
ssl.setEnabledCipherSuites(ssl.getSupportedCipherSuites());
String[] res = ssl.getEnabledCipherSuites();
assertNotNull("NULL result", res);
+ // By default, the socket only supports TLS 1.2, so the TLS 1.3 cipher suites
+ // shouldn't be enabled.
+ List<String> supported = new ArrayList<>(Arrays.asList(ssl.getSupportedCipherSuites()));
+ supported.removeAll(StandardNames.CIPHER_SUITES_TLS13);
assertEquals("not all supported cipher suites were enabled",
- Arrays.asList(ssl.getSupportedCipherSuites()),
+ supported,
Arrays.asList(res));
ssl.close();
}
diff --git a/luni/src/main/java/libcore/internal/Java9LanguageFeatures.java b/luni/src/main/java/libcore/internal/Java9LanguageFeatures.java
deleted file mode 100644
index 7e201d0..0000000
--- a/luni/src/main/java/libcore/internal/Java9LanguageFeatures.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2018 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 libcore.internal;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Proof of concept / dummy code whose only purpose is to demonstrate that Java 9
- * language features are supported in libcore.
- */
-public class Java9LanguageFeatures {
-
- public interface Person {
- String name();
-
- default boolean isPalindrome() {
- return name().equals(reverse(name()));
- }
-
- default boolean isPalindromeIgnoreCase() {
- return name().equalsIgnoreCase(reverse(name()));
- }
-
- // Language feature: private interface method
- private String reverse(String s) {
- return new StringBuilder(s).reverse().toString();
- }
- }
-
- @SafeVarargs
- public static<T> String toListString(T... values) {
- return toString(values).toString();
- }
-
- // Language feature: @SafeVarargs on private methods
- @SafeVarargs
- private static<T> List<String> toString(T... values) {
- List<String> result = new ArrayList<>();
- for (T value : values) {
- result.add(value.toString());
- }
- return result;
- }
-
- public <T> AtomicReference<T> createReference(T content) {
- // Language feature: <> on anonymous class
- return new AtomicReference<>(content) { };
- }
-
- public static byte[] copy(byte[] bytes) throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- InputStream inputStream = new ByteArrayInputStream(bytes);
- try (inputStream) { // Language feature: try on effectively-final variable
- int value;
- while ((value = inputStream.read()) != -1) {
- byteArrayOutputStream.write(value);
- }
- }
- return byteArrayOutputStream.toByteArray();
- }
-
-
-}
diff --git a/luni/src/test/java/libcore/libcore/internal/Java9LanguageFeaturesTest.java b/luni/src/test/java/libcore/libcore/internal/Java9LanguageFeaturesTest.java
deleted file mode 100644
index cc48ec0..0000000
--- a/luni/src/test/java/libcore/libcore/internal/Java9LanguageFeaturesTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2018 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 libcore.libcore.internal;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicReference;
-import junit.framework.TestCase;
-import libcore.internal.Java9LanguageFeatures;
-
-public class Java9LanguageFeaturesTest extends TestCase {
-
- public static class SimplePerson implements Java9LanguageFeatures.Person {
- private final String name;
- public SimplePerson(String name) { this.name = Objects.requireNonNull(name); }
- @Override public String toString() { return "Person: " + name; }
- @Override public String name() { return name; }
- }
-
- public void testPrivateInterfaceMethods() {
- assertFalse(new SimplePerson("Anna").isPalindrome());
- assertTrue(new SimplePerson("Anna").isPalindromeIgnoreCase());
- assertTrue(new SimplePerson("anna").isPalindrome());
- assertTrue(new SimplePerson("bob").isPalindrome());
- assertFalse(new SimplePerson("larry").isPalindrome());
- assertFalse(new SimplePerson("larry").isPalindromeIgnoreCase());
- }
-
- public void testTryOnEffectivelyFinalVariables() throws IOException {
- byte[] data = "Hello, world!".getBytes();
- byte[] dataCopy = Java9LanguageFeatures.copy(data);
- assertTrue(Arrays.equals(data, dataCopy));
- assertTrue(data != dataCopy);
- }
-
- public void testDiamondOnAnonymousClasses() {
- AtomicReference<String> ref = new Java9LanguageFeatures().createReference("Hello, world");
- assertSame("Hello, world", ref.get());
- }
-
- public void testSafeVarargsOnPrivateMethod() {
- assertEquals("[23, and, 42]", Java9LanguageFeatures.toListString(23, "and", 42L));
- }
-
-}
diff --git a/mmodules/libart_oj/Android.bp b/mmodules/libart_oj/Android.bp
index e3d7ded..950e9b1 100644
--- a/mmodules/libart_oj/Android.bp
+++ b/mmodules/libart_oj/Android.bp
@@ -38,7 +38,6 @@
no_standard_libs: true,
libs: ["core.intra.stubs"],
system_modules: "core-intra-stubs-system-modules",
- java_version: "1.9",
openjdk9: {
javacflags: ["--patch-module=java.base=."],
},
diff --git a/mmodules/simple/Android.bp b/mmodules/simple/Android.bp
index ddfed99..94e8164 100644
--- a/mmodules/simple/Android.bp
+++ b/mmodules/simple/Android.bp
@@ -41,7 +41,6 @@
name: "core-simple",
hostdex: true,
defaults: ["core-simple-defaults"],
- java_version: "1.9",
}
// A guaranteed unstripped version of core-simple.
@@ -53,7 +52,6 @@
dex_preopt: {
enabled: false,
},
- java_version: "1.9",
}
// A rule that checks we can build core-simple using only the source for
@@ -95,7 +93,6 @@
no_framework_libs: true,
installable: false,
- java_version: "1.9",
args: "--show-annotation libcore.mmodule.IntraCoreMModuleApi",
}
@@ -114,5 +111,4 @@
openjdk9: {
javacflags: ["--patch-module=java.base=."],
},
- java_version: "1.9",
}
diff --git a/non_openjdk_java_files.bp b/non_openjdk_java_files.bp
index df04980..0b5244c 100644
--- a/non_openjdk_java_files.bp
+++ b/non_openjdk_java_files.bp
@@ -263,7 +263,6 @@
"luni/src/main/java/libcore/icu/NativeConverter.java",
"luni/src/main/java/libcore/icu/RelativeDateTimeFormatter.java",
"luni/src/main/java/libcore/icu/TimeZoneNames.java",
- "luni/src/main/java/libcore/internal/Java9LanguageFeatures.java",
"luni/src/main/java/libcore/internal/StringPool.java",
"luni/src/main/java/libcore/io/AsynchronousCloseMonitor.java",
"luni/src/main/java/libcore/io/ClassPathURLStreamHandler.java",
diff --git a/ojluni/src/main/java/java/lang/Enum.java b/ojluni/src/main/java/java/lang/Enum.java
index 8ada57f..988c133 100644
--- a/ojluni/src/main/java/java/lang/Enum.java
+++ b/ojluni/src/main/java/java/lang/Enum.java
@@ -33,6 +33,7 @@
import java.io.ObjectStreamException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Objects;
import libcore.util.BasicLruCache;
import libcore.util.EmptyArray;
@@ -232,15 +233,13 @@
* is null
* @since 1.5
*/
+ // BEGIN Android-changed: Use a static BasicLruCache mapping Enum class -> Enum instance array.
+ // This change was made to fix a performance regression. See b/4087759 and b/109791362 for more
+ // background information.
public static <T extends Enum<T>> T valueOf(Class<T> enumType,
String name) {
- // Android-changed: Use a static BasicLruCache mapping Enum class -> Enum instance array.
- if (enumType == null) {
- throw new NullPointerException("enumType == null");
- }
- if (name == null) {
- throw new NullPointerException("name == null");
- }
+ Objects.requireNonNull(enumType, "enumType == null");
+ Objects.requireNonNull(enumType, "name == null");
T[] values = getSharedConstants(enumType);
if (values == null) {
throw new IllegalArgumentException(enumType.toString() + " is not an enum type.");
@@ -258,23 +257,24 @@
"No enum constant " + enumType.getCanonicalName() + "." + name);
}
+ private static Object[] enumValues(Class<? extends Enum> clazz) {
+ if (!clazz.isEnum()) {
+ // Either clazz is Enum.class itself, or it is not an enum class and the method was
+ // called unsafely e.g. using an unchecked cast or via reflection.
+ return null;
+ }
+ try {
+ Method valueMethod = clazz.getDeclaredMethod("values");
+ return (Object[]) valueMethod.invoke(null);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
private static final BasicLruCache<Class<? extends Enum>, Object[]> sharedConstantsCache
= new BasicLruCache<Class<? extends Enum>, Object[]>(64) {
@Override protected Object[] create(Class<? extends Enum> enumType) {
- if (!enumType.isEnum()) {
- return null;
- }
- try {
- Method method = enumType.getDeclaredMethod("values", EmptyArray.CLASS);
- method.setAccessible(true);
- return (Object[]) method.invoke((Object[]) null);
- } catch (NoSuchMethodException impossible) {
- throw new AssertionError("impossible", impossible);
- } catch (IllegalAccessException impossible) {
- throw new AssertionError("impossible", impossible);
- } catch (InvocationTargetException impossible) {
- throw new AssertionError("impossible", impossible);
- }
+ return enumValues(enumType);
}
};
@@ -288,6 +288,7 @@
public static <T extends Enum<T>> T[] getSharedConstants(Class<T> enumType) {
return (T[]) sharedConstantsCache.get(enumType);
}
+ // END Android-changed: Use a static BasicLruCache mapping Enum class -> Enum instance array.
/**
* enum classes cannot have finalize methods.
diff --git a/support/src/test/java/libcore/java/security/StandardNames.java b/support/src/test/java/libcore/java/security/StandardNames.java
index 3369293..3ca3501 100644
--- a/support/src/test/java/libcore/java/security/StandardNames.java
+++ b/support/src/test/java/libcore/java/security/StandardNames.java
@@ -264,6 +264,7 @@
provide("SSLContext", "TLSv1");
provide("SSLContext", "TLSv1.1");
provide("SSLContext", "TLSv1.2");
+ provide("SSLContext", "TLSv1.3");
provide("SecretKeyFactory", "DES");
provide("SecretKeyFactory", "DESede");
provide("SecretKeyFactory", "PBEWithMD5AndDES");
@@ -683,7 +684,8 @@
public static final Set<String> SSL_SOCKET_PROTOCOLS = new HashSet<String>(Arrays.asList(
"TLSv1",
"TLSv1.1",
- "TLSv1.2"));
+ "TLSv1.2",
+ "TLSv1.3"));
public static final Set<String> SSL_SOCKET_PROTOCOLS_CLIENT_DEFAULT =
new HashSet<String>(Arrays.asList(
"TLSv1",
@@ -710,11 +712,13 @@
}
}
- private static enum TLSVersion {
+ private enum TLSVersion {
SSLv3("SSLv3"),
TLSv1("TLSv1"),
TLSv11("TLSv1.1"),
- TLSv12("TLSv1.2");
+ TLSv12("TLSv1.2"),
+ TLSv13("TLSv1.3"),
+ ;
private final String name;
@@ -735,8 +739,9 @@
/**
* Valid values for X509TrustManager.checkServerTrusted authType,
- * either key exchange algorithm part of the cipher suite
- * or UNKNOWN.
+ * either key exchange algorithm part of the cipher suite, UNKNOWN,
+ * or GENERIC (for TLS 1.3 cipher suites that don't imply a specific
+ * key exchange method).
*/
public static final Set<String> SERVER_AUTH_TYPES = new HashSet<String>(Arrays.asList(
"DHE_DSS",
@@ -756,7 +761,8 @@
"ECDH_RSA",
"ECDHE_ECDSA",
"ECDHE_RSA",
- "UNKNOWN"));
+ "UNKNOWN",
+ "GENERIC"));
public static final String CIPHER_SUITE_INVALID = "SSL_NULL_WITH_NULL_NULL";
@@ -811,6 +817,11 @@
addOpenSsl("TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256");
addOpenSsl("TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256");
+ // TLSv1.3 cipher suites
+ addOpenSsl("TLS_AES_128_GCM_SHA256");
+ addOpenSsl("TLS_AES_256_GCM_SHA384");
+ addOpenSsl("TLS_CHACHA20_POLY1305_SHA256");
+
// Pre-Shared Key (PSK) cipher suites
addOpenSsl("TLS_PSK_WITH_AES_128_CBC_SHA");
addOpenSsl("TLS_PSK_WITH_AES_256_CBC_SHA");
@@ -943,6 +954,14 @@
"SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA"
);
+ /**
+ * Cipher suites that are only supported with TLS 1.3.
+ */
+ public static final List<String> CIPHER_SUITES_TLS13 = Arrays.asList(
+ "TLS_AES_128_GCM_SHA256",
+ "TLS_AES_256_GCM_SHA384",
+ "TLS_CHACHA20_POLY1305_SHA256");
+
// NOTE: This list needs to be kept in sync with Javadoc of javax.net.ssl.SSLSocket and
// javax.net.ssl.SSLEngine.
private static final List<String> CIPHER_SUITES_ANDROID_AES_HARDWARE = Arrays.asList(