Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions src/main/java/org/apache/jasper/compiler/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2184,10 +2184,6 @@ 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 @@ -2351,6 +2347,18 @@ 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 @@ -2383,15 +2391,6 @@ 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 @@ -2403,8 +2402,10 @@ private void generateCustomEnd(Node.CustomTag n, String tagHandlerVar,
writeDestroyInstance(tagHandlerVar);
}

out.popIndent();
out.printil("}");
if (n.implementsTryCatchFinally()) {
out.popIndent();
out.printil("}");
}

// Declare and synchronize AT_END scripting variables (must do this
// outside the try/catch/finally block)
Expand All @@ -2429,9 +2430,15 @@ private void generateCustomDoTag(Node.CustomTag n,
declareScriptingVars(n, VariableInfo.AT_BEGIN);
saveScriptingVars(n, VariableInfo.AT_BEGIN);

// Declare AT_END scripting variables
declareScriptingVars(n, VariableInfo.AT_END);

String tagHandlerClassName = tagHandlerClass.getCanonicalName();
writeNewInstance(tagHandlerVar, tagHandlerClassName);

out.printil("try {");
out.pushIndent();

generateSetters(n, tagHandlerVar, handlerInfo, true);

// JspIdConsumer (after context has been set)
Expand Down Expand Up @@ -2479,13 +2486,19 @@ private void generateCustomDoTag(Node.CustomTag n,
// Synchronize AT_BEGIN scripting variables
syncScriptingVars(n, VariableInfo.AT_BEGIN);

// Declare and synchronize AT_END scripting variables
declareScriptingVars(n, VariableInfo.AT_END);
// Synchronize AT_END scripting variables
syncScriptingVars(n, VariableInfo.AT_END);

out.popIndent();
out.printil("} finally {");
out.pushIndent();

// Resource injection
writeDestroyInstance(tagHandlerVar);

out.popIndent();
out.printil("}");

n.setEndJavaLine(out.getJavaLine());
}

Expand Down