This is an automated email from the ASF dual-hosted git repository. jtulach pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans-html4j.git
commit eb8179dc9a67de9b0aebd2b18ddfd6277a508f0e Author: Jaroslav Tulach <jaroslav.tul...@apidesign.org> AuthorDate: Sat May 4 09:00:39 2019 +0200 Avoid null presenter as soon as possible --- boot/src/main/java/org/netbeans/html/boot/spi/Fn.java | 4 ++++ boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java | 5 +++++ .../src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/boot/src/main/java/org/netbeans/html/boot/spi/Fn.java b/boot/src/main/java/org/netbeans/html/boot/spi/Fn.java index 3dc4e30..0b8eb35 100644 --- a/boot/src/main/java/org/netbeans/html/boot/spi/Fn.java +++ b/boot/src/main/java/org/netbeans/html/boot/spi/Fn.java @@ -169,9 +169,13 @@ public abstract class Fn { * * @param p the presenter that should be active until closable is closed * @return the closable to close + * @throws NullPointerException if the {@code p} is {@code null} * @since 0.7 */ public static Closeable activate(Presenter p) { + if (p == null) { + throw new NullPointerException(); + } return FnContext.activate(p); } diff --git a/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java b/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java index 89689bc..60a824a 100644 --- a/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java +++ b/boot/src/test/java/org/netbeans/html/boot/impl/FnTest.java @@ -124,6 +124,11 @@ public class FnTest extends JsClassLoaderBase { methodClass = loader.loadClass(JsMethods.class.getName()); close.close(); } + + @Test(expectedExceptions = NullPointerException.class) + public void nullProcessorNPE() { + Fn.activate(null); + } @Test public void flushingPresenter() throws IOException { class FP implements Fn.Presenter, Flushable { diff --git a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java index e37ffec..06aafaf 100644 --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java @@ -205,7 +205,7 @@ public class JsClassLoaderBase { @Test public void plusOrMul() throws Throwable { Method st = methodClass.getMethod("plusOrMul", int.class, int.class); assertNotNull(Fn.activePresenter(), "Is there a presenter?"); - Closeable c = Fn.activate(null); + Closeable c = FnContext.activate(null); try { assertNull(Fn.activePresenter(), "No presenter now"); assertEquals(st.invoke(null, 6, 7), 42, "Mul in Java"); @@ -214,7 +214,7 @@ public class JsClassLoaderBase { } assertNotNull(Fn.activePresenter(), "Is there a presenter again"); assertEquals(st.invoke(null, 6, 7), 13, "Plus in JavaScript"); - c = Fn.activate(null); + c = FnContext.activate(null); try { assertNull(Fn.activePresenter(), "No presenter again"); assertEquals(st.invoke(null, 6, 7), 42, "Mul in Java"); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists