Skip to content

Commit

Permalink
[UNDERTOW-2401] Improve error handling for tags to ensure the tag is …
Browse files Browse the repository at this point in the history
…still released/destroyed after exception
  • Loading branch information
aogburn committed Jun 13, 2024
1 parent cb8e98e commit 39d0732
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/main/java/org/apache/jasper/compiler/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(");
Expand All @@ -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)
Expand Down

0 comments on commit 39d0732

Please sign in to comment.