-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: flushes ByteArrayOutputStream before using #266
Conversation
lang/src/main/java/org/apache/shiro/lang/io/DefaultSerializer.java
Outdated
Show resolved
Hide resolved
@lcc did you run into an issue with this? |
Thank for the prompt response bdemers. I didn't run into any problems, I was just running a code analyzer and found what appeared to be a bug. Sorry for the useless PR, do you want me to close it? |
Can you share the result from the analyzer? |
It's a runtime code analysis tool, javaMOP, and the output is basically the file and the line number of the spec violation (in this case the spec was ByteArrayOutputStream_FlushBeforeRetrieve).
The ouput of the tool is: |
I'm not against the change, I'm just trying to understand the background a bit more. like are there are current JVMs that do something different (meaning I should check for this in other projects) Or if this static checking tool is something we should add to Shiro. |
This tool is not static though, the violations are discovered at runtime when I was running shiro tests.
|
Does it attach as an agent can you point me to the tool's site? (I like these kinds of tools) As for my other comment:
Sorry, that was a bit poorly worded, I just meant. If there are other JVMs (for example projects like Android, Substrate, etc) where the implementation of ByteArrayOutputStream is different, then this issue becomes more important (for both Shiro and other projects). |
Yes, it attaches as an agent.
That's actually really interesting, I think it would be a really good idea to take a look at this! Requested links: |
Thanks @lcc! |
Hi, I would like to start by saying I am sorry for not following your community guidelines but since this patch is really tiny, I didn't think it would be necessary to create a task at Jira or follow the other procedures, if this is considered unnaceptable, do let me know and I will open this PR as specified. Thanks for the comprehension.
Flushes OutputStream before using the underlying ByteArrayOutputStream: when an OutputStream (or its subclass) instance is built on top of an underlying ByteArrayOutputStream instance, it should be flushed or closed before the underlying instance's toByteArray() is invoked. Failing to fulfill this requirement may cause toByteArray() to return incomplete contents.