From fe8d4a52de6e0ce2ac8c80190e4a6acf895730f6 Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Mon, 27 Nov 2023 16:10:30 +0100 Subject: [PATCH 1/6] Implement BadFactoryTest in pure Java --- .../script/JDK_8196959/BadFactoryTest.java | 27 ++++++++- .../script/JDK_8196959/BadFactoryTest.sh | 60 ------------------- 2 files changed, 25 insertions(+), 62 deletions(-) delete mode 100644 test/jdk/javax/script/JDK_8196959/BadFactoryTest.sh diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java index 9f02c61511d0d..a9f601f1f9a0d 100644 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java +++ b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -21,10 +21,33 @@ * questions. */ +/* + * @test + * @bug 8196959 + * @summary BadFactory that results in NPE being thrown from ScriptEngineManager + * @library /javax/script/JDK_8196959 + * @build BadFactory BadFactoryTest + * @run junit/othervm BadFactoryTest + * @run junit/othervm -Djava.security.manager=allow BadFactoryTest + */ + +import org.junit.jupiter.api.Test; + +import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class BadFactoryTest { - public static void main(String[] args) { + + @Test + public void scriptEngineManagerShouldLoadBadFactory() { ScriptEngineManager m = new ScriptEngineManager(); + // Sanity check that ScriptEngineManager loads the BadFactory + Optional badFactory = m.getEngineFactories().stream() + .filter(fac -> fac.getClass() == BadFactory.class) + .findAny(); + assertTrue(badFactory.isPresent(), "BadFactory not loaded"); } } diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.sh b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.sh deleted file mode 100644 index 21becec9f7134..0000000000000 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.sh +++ /dev/null @@ -1,60 +0,0 @@ -# -# Copyright (c) 2018, 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 -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# - -# @test -# @bug 8196959 -# @summary BadFactory that results in NPE being thrown from ScriptEngineManager -# -# @build BadFactory BadFactoryTest -# @run shell BadFactoryTest.sh - -if [ "${TESTSRC}" = "" ] -then - echo "TESTSRC not set. Test cannot execute. Failed." - exit 1 -fi - -. ${TESTSRC}/../CommonSetup.sh - -echo "Creating JAR file ..." - -$JAR ${TESTTOOLVMOPTS} -cf ${TESTCLASSES}/badfactory.jar \ - -C ${TESTCLASSES} BadFactory.class \ - -C ${TESTCLASSES} BadFactoryTest.class \ - -C "${TESTSRC}" META-INF/services/javax.script.ScriptEngineFactory - -echo "Running test with security manager ..." -$JAVA ${TESTVMOPTS} -Djava.security.manager -classpath \ - "${TESTCLASSES}${PS}${TESTCLASSES}/badfactory.jar" \ - BadFactoryTest - -ret=$? -if [ $ret -ne 0 ] -then - exit $ret -fi - -echo "Running test without security manager ..." -$JAVA ${TESTVMOPTS} -classpath \ - "${TESTCLASSES}${PS}${TESTCLASSES}/badfactoty.jar" \ - BadFactoryTest From 17894b851fe884f6aa6be566848bde058d71e15d Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Mon, 27 Nov 2023 18:34:33 +0100 Subject: [PATCH 2/6] Add comment describing the initialization of ScriptEngineManager --- test/jdk/javax/script/JDK_8196959/BadFactoryTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java index a9f601f1f9a0d..3a6c2275c4e87 100644 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java +++ b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java @@ -43,11 +43,14 @@ public class BadFactoryTest { @Test public void scriptEngineManagerShouldLoadBadFactory() { + // Check that ScriptEngineManager initializes even in the + // presence of a ScriptEngineFactory returning nulls ScriptEngineManager m = new ScriptEngineManager(); - // Sanity check that ScriptEngineManager loads the BadFactory + + // Sanity check that ScriptEngineManager actually found the BadFactory Optional badFactory = m.getEngineFactories().stream() .filter(fac -> fac.getClass() == BadFactory.class) .findAny(); - assertTrue(badFactory.isPresent(), "BadFactory not loaded"); + assertTrue(badFactory.isPresent(), "BadFactory not found"); } } From 5de709b0ce8e930de5d28cb742ea7fa3a460c7b0 Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Mon, 27 Nov 2023 18:46:57 +0100 Subject: [PATCH 3/6] Update the @summary to describe the purpose of the test, not the BadFactory --- test/jdk/javax/script/JDK_8196959/BadFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java index 3a6c2275c4e87..9a06354ab7ca1 100644 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java +++ b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java @@ -24,7 +24,7 @@ /* * @test * @bug 8196959 - * @summary BadFactory that results in NPE being thrown from ScriptEngineManager + * @summary Verify that ScriptEngineManager can load BadFactory without throwing NPE * @library /javax/script/JDK_8196959 * @build BadFactory BadFactoryTest * @run junit/othervm BadFactoryTest From 2404ea750410824c2e301056e3c2cfc651f1f9a1 Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Tue, 28 Nov 2023 13:03:15 +0100 Subject: [PATCH 4/6] Move jtreg tags from before to after imports --- .../script/JDK_8196959/BadFactoryTest.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java index 9a06354ab7ca1..760381810432e 100644 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java +++ b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java @@ -21,6 +21,14 @@ * questions. */ +import org.junit.jupiter.api.Test; + +import javax.script.ScriptEngineFactory; +import javax.script.ScriptEngineManager; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertTrue; + /* * @test * @bug 8196959 @@ -30,15 +38,6 @@ * @run junit/othervm BadFactoryTest * @run junit/othervm -Djava.security.manager=allow BadFactoryTest */ - -import org.junit.jupiter.api.Test; - -import javax.script.ScriptEngineFactory; -import javax.script.ScriptEngineManager; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertTrue; - public class BadFactoryTest { @Test From f2f15cec37171045b73283a8e3b3d3365eb3985d Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Tue, 28 Nov 2023 14:56:37 +0100 Subject: [PATCH 5/6] Add the Java rewrite issue to the @bug list --- test/jdk/javax/script/JDK_8196959/BadFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java index 760381810432e..eb140fc791166 100644 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java +++ b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java @@ -31,7 +31,7 @@ /* * @test - * @bug 8196959 + * @bug 8196959 8320712 * @summary Verify that ScriptEngineManager can load BadFactory without throwing NPE * @library /javax/script/JDK_8196959 * @build BadFactory BadFactoryTest From db67d8d9e5f924c371053b139d24593686b16ec8 Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Wed, 24 Jan 2024 07:46:20 +0100 Subject: [PATCH 6/6] Remove the @library tag, the META-INF service definition file is already on the classpath --- test/jdk/javax/script/JDK_8196959/BadFactoryTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java index eb140fc791166..36e3391be7fe2 100644 --- a/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java +++ b/test/jdk/javax/script/JDK_8196959/BadFactoryTest.java @@ -33,7 +33,6 @@ * @test * @bug 8196959 8320712 * @summary Verify that ScriptEngineManager can load BadFactory without throwing NPE - * @library /javax/script/JDK_8196959 * @build BadFactory BadFactoryTest * @run junit/othervm BadFactoryTest * @run junit/othervm -Djava.security.manager=allow BadFactoryTest