diff --git a/jcl/src/java.base/share/classes/java/lang/String.java b/jcl/src/java.base/share/classes/java/lang/String.java index 966e8cdd3f2..12c58beb824 100644 --- a/jcl/src/java.base/share/classes/java/lang/String.java +++ b/jcl/src/java.base/share/classes/java/lang/String.java @@ -8298,14 +8298,6 @@ public static String join(CharSequence delimiter, Iterable describeConstable() { - throw new UnsupportedOperationException("Stub for Java 12 compilation (Jep334)"); - } - - public String resolveConstantDesc(MethodHandles.Lookup lookup) { - throw new UnsupportedOperationException("Stub for Java 12 compilation (Jep334)"); - } - /** * Apply a function to this string. The function expects a single String input and returns an R. * @@ -8315,5 +8307,26 @@ public String resolveConstantDesc(MethodHandles.Lookup lookup) { public R transform(Function f) { return f.apply(this); } + + /** + * Returns the nominal descriptor of this String instance, or an empty optional + * if construction is not possible. + * + * @return Optional with nominal descriptor of String instance + */ + public Optional describeConstable() { + return Optional.of(this); + } + + /** + * Resolves this ConstantDesc instance + * + * @param lookup parameter is ignored + * + * @return the resolved Constable value + */ + public String resolveConstantDesc(MethodHandles.Lookup lookup) { + return this; + } /*[ENDIF] Java12 */ } diff --git a/test/README.md b/test/README.md index cd9877e04c2..f91135f30a4 100644 --- a/test/README.md +++ b/test/README.md @@ -1,5 +1,5 @@ + + + + + Tests for Java 12 and up + + + + + + + + + + + + + + + + + Ant version is ${ant.version} + ============COMPILER SETTINGS============ + ===fork: yes + ===executable: ${compiler.javac} + ===debug: on + ===destdir: ${DEST} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/Java12andUp/playlist.xml b/test/functional/Java12andUp/playlist.xml new file mode 100644 index 00000000000..d6ea012794a --- /dev/null +++ b/test/functional/Java12andUp/playlist.xml @@ -0,0 +1,48 @@ + + + + + + + Jep334Tests + + NoOptions + + $(JAVA_COMMAND) $(JVM_OPTIONS) \ + -cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)GeneralTest.jar$(Q) \ + org.testng.TestNG -d $(REPORTDIR) $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -testnames Jep334Tests \ + -groups $(TEST_GROUP) \ + -excludegroups $(DEFAULT_EXCLUDE); \ + $(TEST_STATUS) + + + sanity + + + functional + + + 12+ + + + diff --git a/test/functional/Java12andUp/src/org/openj9/test/java_lang/Test_String.java b/test/functional/Java12andUp/src/org/openj9/test/java_lang/Test_String.java new file mode 100644 index 00000000000..9254c7f5fd6 --- /dev/null +++ b/test/functional/Java12andUp/src/org/openj9/test/java_lang/Test_String.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2018, 2019 IBM Corp. and others + * + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which accompanies this + * distribution and is available at https://www.eclipse.org/legal/epl-2.0/ + * or the Apache License, Version 2.0 which accompanies this distribution and + * is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following + * Secondary Licenses when the conditions for such availability set + * forth in the Eclipse Public License, v. 2.0 are satisfied: GNU + * General Public License, version 2 with the GNU Classpath + * Exception [1] and GNU General Public License, version 2 with the + * OpenJDK Assembly Exception [2]. + * + * [1] https://www.gnu.org/software/classpath/license.html + * [2] http://openjdk.java.net/legal/assembly-exception.html + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception + *******************************************************************************/ +package org.openj9.test.java_lang; + +import org.testng.Assert; +import org.testng.annotations.Test; +import org.testng.log4testng.Logger; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodHandles.Lookup; +import java.util.Optional; + +/** + * This test Java.lang.String API added in Java 12 and later version. + * + */ +public class Test_String { + public static Logger logger = Logger.getLogger(Test_String.class); + + private String empty = ""; + private String latin1 = "abc123"; + private String nonLatin1 = "abc\u0153"; + private String emptyWithTerm = "\n"; + + /* + * Test Java 12 API String.describeConstable() + */ + @Test(groups = { "level.sanity" }) + public void testStringDescribeConstable() throws Throwable { + testStringDescribeConstable_sub(empty); + testStringDescribeConstable_sub(latin1); + testStringDescribeConstable_sub(nonLatin1); + testStringDescribeConstable_sub(emptyWithTerm); + } + + private void testStringDescribeConstable_sub(String test) throws Throwable { + logger.debug("testStringDescribeConstable: test with string: " + test); + Optional optionalTest = test.describeConstable(); + String describedTestString = optionalTest.orElseThrow(); + Assert.assertTrue(test.equals(describedTestString)); + } + + /* + * Test Java 12 API String.resolveConstantDesc() + */ + @Test(groups = { "level.sanity" }) + public void testStringResolveConstantDesc() { + testStringResolveConstantDesc_sub(empty); + testStringResolveConstantDesc_sub(latin1); + testStringResolveConstantDesc_sub(nonLatin1); + testStringResolveConstantDesc_sub(emptyWithTerm); + } + + private void testStringResolveConstantDesc_sub(String test) { + logger.debug("testStringDescribeConstable: test with string: " + test); + + /* run test with a valid lookup */ + MethodHandles.Lookup lookup = MethodHandles.publicLookup(); + String resolvedTest = test.resolveConstantDesc(lookup); + Assert.assertTrue(test.equals(resolvedTest)); + + /* run tests with a null lookup (should be ignored) */ + String resolvedTest2 = test.resolveConstantDesc(null); + Assert.assertTrue(test.equals(resolvedTest2)); + } + +} diff --git a/test/functional/Java12andUp/testng.xml b/test/functional/Java12andUp/testng.xml new file mode 100644 index 00000000000..2c30c2eed6c --- /dev/null +++ b/test/functional/Java12andUp/testng.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + +