diff --git a/src/main/java/org/apache/jasper/compiler/Generator.java b/src/main/java/org/apache/jasper/compiler/Generator.java index 8122ad3..beebe63 100644 --- a/src/main/java/org/apache/jasper/compiler/Generator.java +++ b/src/main/java/org/apache/jasper/compiler/Generator.java @@ -2184,6 +2184,10 @@ private void generateCustomStart(Node.CustomTag n, writeNewInstance(tagHandlerVar, tagHandlerClassName); } + // Wrap use of tag in try/finally to ensure clean-up takes place + out.printil("try {"); + out.pushIndent(); + // includes setting the context generateSetters(n, tagHandlerVar, handlerInfo, false); @@ -2347,18 +2351,6 @@ private void generateCustomEnd(Node.CustomTag n, String tagHandlerVar, out.print(tagHandlerVar); printlnThreePart(out, ".doEndTag() == ", TAG, ".SKIP_PAGE) {"); out.pushIndent(); - if (!n.implementsTryCatchFinally()) { - if (isPoolingEnabled && !(n.implementsJspIdConsumer())) { - out.printin(n.getTagHandlerPoolName()); - out.print(".reuse("); - out.print(tagHandlerVar); - out.println(");"); - } else { - out.printin(tagHandlerVar); - out.println(".release();"); - writeDestroyInstance(tagHandlerVar); - } - } if (isTagFile || isFragment) { printilThreePart(out, "throw new ", SKIP_PAGE_EXCEPTION, "();"); } else { @@ -2391,6 +2383,15 @@ private void generateCustomEnd(Node.CustomTag n, String tagHandlerVar, out.println(".doFinally();"); } + if (n.implementsTryCatchFinally()) { + out.popIndent(); + out.printil("}"); + } + + // Ensure clean-up takes place + out.popIndent(); + out.printil("} finally {"); + out.pushIndent(); if (isPoolingEnabled && !(n.implementsJspIdConsumer())) { out.printin(n.getTagHandlerPoolName()); out.print(".reuse("); @@ -2406,6 +2407,8 @@ private void generateCustomEnd(Node.CustomTag n, String tagHandlerVar, out.popIndent(); out.printil("}"); } + out.popIndent(); + out.printil("}"); // Declare and synchronize AT_END scripting variables (must do this // outside the try/catch/finally block)