-
Notifications
You must be signed in to change notification settings - Fork 807
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
Fix meaningless close #445
Conversation
Tests fail |
Hi @lukaszlenart thanks for the prompt response. The error that causes the pipeline to fail is "ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter" which also happens in the current master build. This is a well known error in the maven surefire plugin, in order to "fix" this one must update to a surefire version to one that already corrected it, such as 3.0.0-M1. After updating it on my surefire-plugin, this issue ceases to exist and all tests pass. This PR was purely meant to fix unecessary uses of the close method, but if you want I can write a patch for the surefire-plugin. I didn't do it before because there may be some underlying reason to use it the way it's being used. |
As far I see there is a compilation error
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Lucas.
I think that the CharArrayWriter
close()
changes are OK, being no-ops as you pointed out.
The change to StrutsSpringPortletMockObjectsTest
should probably be reverted, though, since it causes the compilation of your PR to fail.
Thanks,
James.
@@ -209,7 +209,6 @@ String getText(Mark start, Mark stop) throws JasperException { | |||
CharArrayWriter caw = new CharArrayWriter(); | |||
while (!stop.equals(mark())) | |||
caw.write(nextChar()); | |||
caw.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API Docs and JDK source confirm that for CharArrayWriter
instances, calls to close()
are no-ops (no effect).
So I think this should be a safe change.
@@ -595,7 +594,6 @@ private void pushFile(String file, String encoding, | |||
char buf[] = new char[1024]; | |||
for (int i = 0 ; (i = reader.read(buf)) != -1 ;) | |||
caw.write(buf, 0, i); | |||
caw.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for here.
@@ -324,7 +324,6 @@ private String parseScriptText(String tx) { | |||
++i; | |||
} | |||
} | |||
cw.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
@@ -222,7 +222,8 @@ public void testMockClientDataRequest() { | |||
assertEquals("Content-type not as expected ?", TEST_CONTENT_TYPE, mockClientDataRequest.getContentType()); | |||
mockClientDataRequest.setMethod(TEST_METHOD); | |||
assertEquals("Method not as expected ?", TEST_METHOD, mockClientDataRequest.getMethod()); | |||
try ( InputStream inputStream = mockClientDataRequest.getPortletInputStream() ) { | |||
InputStream inputStream = mockClientDataRequest.getPortletInputStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change in the PR should probably be reverted. The previous try-with-resources call is safer, and restoring that code should eliminate the IOException
issue currently being reported during the compilation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, the PR has now been updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Meaningless Close: In several classes, close(), specified in Closeable interface, has no effect and other methods in those classes can be called after close() without IOException.