First attempt to describe an what is wrong when presenter is not active.
1.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Mon Sep 01 15:36:39 2014 +0200
1.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Mon Sep 01 15:36:48 2014 +0200
1.3 @@ -324,10 +324,8 @@
1.4 "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;"
1.5 );
1.6 Label noPresenter = new Label();
1.7 - if (hasCode) {
1.8 - super.visitInsn(Opcodes.DUP);
1.9 - super.visitJumpInsn(Opcodes.IFNULL, noPresenter);
1.10 - }
1.11 + super.visitInsn(Opcodes.DUP);
1.12 + super.visitJumpInsn(Opcodes.IFNULL, noPresenter);
1.13 if (resource != null) {
1.14 super.visitLdcInsn(Type.getObjectType(FindInClass.this.name));
1.15 super.visitLdcInsn(resource);
1.16 @@ -500,9 +498,17 @@
1.17 );
1.18 super.visitInsn(Opcodes.RETURN);
1.19 }
1.20 + super.visitLabel(noPresenter);
1.21 if (hasCode) {
1.22 - super.visitLabel(noPresenter);
1.23 super.visitCode();
1.24 + } else {
1.25 + super.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
1.26 + super.visitInsn(Opcodes.DUP);
1.27 + super.visitLdcInsn("No presenter active. Use BrwsrCtx.execute!");
1.28 + super.visitMethodInsn(Opcodes.INVOKESPECIAL,
1.29 + "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V"
1.30 + );
1.31 + this.visitInsn(Opcodes.ATHROW);
1.32 }
1.33 return true;
1.34 }
2.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Mon Sep 01 15:36:39 2014 +0200
2.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsClassLoaderBase.java Mon Sep 01 15:36:48 2014 +0200
2.3 @@ -46,7 +46,10 @@
2.4 import java.lang.reflect.InvocationTargetException;
2.5 import java.lang.reflect.Method;
2.6 import java.lang.reflect.Modifier;
2.7 +import java.util.logging.Level;
2.8 +import java.util.logging.Logger;
2.9 import org.netbeans.html.boot.spi.Fn;
2.10 +import org.testng.Assert;
2.11 import static org.testng.Assert.*;
2.12 import org.testng.annotations.BeforeMethod;
2.13 import org.testng.annotations.Test;
2.14 @@ -233,4 +236,21 @@
2.15 assertEquals(res.length, 1, "One element");
2.16 assertEquals(res[0], "Ahoj", "The right string");
2.17 }
2.18 -}
2.19 \ No newline at end of file
2.20 +
2.21 + @Test public void checkTheTypeOfThrownException() throws Throwable {
2.22 + FnContext.currentPresenter(null);
2.23 + assertNull(Fn.activePresenter(), "No presenter is activer right now");
2.24 + Object res = null;
2.25 + try {
2.26 + Method st = methodClass.getMethod("plus", int.class, int.class);
2.27 + try {
2.28 + res = st.invoke(null, 40, 2);
2.29 + } catch (InvocationTargetException ex) {
2.30 + throw ex.getTargetException();
2.31 + }
2.32 + } catch (IllegalStateException ex) {
2.33 + assertEquals(ex.getMessage(), "No presenter active. Use BrwsrCtx.execute!");
2.34 + }
2.35 + Assert.fail("Native method should throw IllegalStateException. Was: " + res);
2.36 + }
2.37 +}