Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use try-with-resources. #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arturobernalg
Copy link
Member

No description provided.

@juanpablo-santos
Copy link
Contributor

conflicts with latest merge, please update the PR

@arturobernalg
Copy link
Member Author

conflicts with latest merge, please update the PR

solved

Copy link
Contributor

@juanpablo-santos juanpablo-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concerns with closing JSPWriter stream from pageContext, please review

@@ -108,8 +108,9 @@ public final int doStartTag() {
public final int doAfterBody() {
if( bodyContent != null ) {
try {
final JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
try (JspWriter out = getPreviousOut()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per JSPWriter#close, this method shouldn't be invoked directly.

Furthermore, JSPWriter#flush states [...] Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown., so once this stream is closed, after the custom tags is rendered, the rest of the JSP wouldn't be rendered and will yield an exception? Would you mind verifying if this is the case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per JSPWriter#close, this method shouldn't be invoked directly.

Furthermore, JSPWriter#flush states [...] Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown., so once this stream is closed, after the custom tags is rendered, the rest of the JSP wouldn't be rendered and will yield an exception? Would you mind verifying if this is the case?

Hey @juanpablo-santos I'll take a look. I'll let you know. In the meantime, what do you think about leaving the PR open?
TY

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @juanpablo-santos

You are absolutely right. After reviewing the JSPWriter documentation and the code again, I agree that closing the JSPWriter stream within the doAfterBody() method could potentially cause an IOException in the subsequent operations by the JSP engine.

I had introduced the try-with-resources to ensure proper resource handling. However, in this context, the JSP engine manages the lifecycle of the JSPWriter stream, and it is best not to interfere with this management.

Therefore, I will revert the try-with-resources change for the JspWriter out stream. Thank you for catching this and for your valuable feedback.

@juanpablo-santos
Copy link
Contributor

Hi! just've seen now a pending review here - there're still a bunch of try (JspWriter out = pageContext.getOut()) { that should be reverted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants