|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
21 | 21 | * questions.
|
22 | 22 | */
|
23 | 23 |
|
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import javax.script.ScriptEngineFactory; |
24 | 27 | import javax.script.ScriptEngineManager;
|
| 28 | +import java.util.Optional; |
| 29 | + |
| 30 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
25 | 31 |
|
| 32 | +/* |
| 33 | + * @test |
| 34 | + * @bug 8196959 8320712 |
| 35 | + * @summary Verify that ScriptEngineManager can load BadFactory without throwing NPE |
| 36 | + * @build BadFactory BadFactoryTest |
| 37 | + * @run junit/othervm BadFactoryTest |
| 38 | + * @run junit/othervm -Djava.security.manager=allow BadFactoryTest |
| 39 | + */ |
26 | 40 | public class BadFactoryTest {
|
27 |
| - public static void main(String[] args) { |
| 41 | + |
| 42 | + @Test |
| 43 | + public void scriptEngineManagerShouldLoadBadFactory() { |
| 44 | + // Check that ScriptEngineManager initializes even in the |
| 45 | + // presence of a ScriptEngineFactory returning nulls |
28 | 46 | ScriptEngineManager m = new ScriptEngineManager();
|
| 47 | + |
| 48 | + // Sanity check that ScriptEngineManager actually found the BadFactory |
| 49 | + Optional<ScriptEngineFactory> badFactory = m.getEngineFactories().stream() |
| 50 | + .filter(fac -> fac.getClass() == BadFactory.class) |
| 51 | + .findAny(); |
| 52 | + assertTrue(badFactory.isPresent(), "BadFactory not found"); |
29 | 53 | }
|
30 | 54 | }
|
0 commit comments