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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer close OutputStream that is passed into JsonSerializer #2029

Merged
merged 4 commits into from May 17, 2022

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented May 10, 2022

馃摐 Description

No longer (auto) close the OutputStream that is passed into JsonSerializer. This caused problems when passing in System.out from StdoutTransport as it closed the stream.

馃挕 Motivation and Context

Fixes #2027 for 6.x

馃挌 How did you test it?

  • Unit Test
  • code sample

馃摑 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

馃敭 Next steps

@adinauer adinauer changed the title Do not close stream that is passed into JsonSerializer No longer close OutputStream that is passed into JsonSerializer May 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 10, 2022

Codecov Report

Merging #2029 (80a7b18) into 6.x.x (f60ace2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              6.x.x    #2029   +/-   ##
=========================================
  Coverage     80.79%   80.80%           
- Complexity     3146     3147    +1     
=========================================
  Files           228      228           
  Lines         11645    11645           
  Branches       1565     1565           
=========================================
+ Hits           9409     9410    +1     
+ Misses         1649     1648    -1     
  Partials        587      587           
Impacted Files Coverage 螖
sentry/src/main/java/io/sentry/JsonSerializer.java 97.91% <100.00%> (酶)
...ry/src/main/java/io/sentry/SentryEnvelopeItem.java 87.41% <0.00%> (+0.69%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update f60ace2...80a7b18. Read the comment docs.

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

LGTM 馃憤 Just one idea maybe - not sure if it'd make sense to introduce another method overload, which accepts a boolean like autoClose? Probably not needed though

}
writer.flush();
Copy link
Contributor

Choose a reason for hiding this comment

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

should be likely in the finally block?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only moved the code around. There's a catch block that only logs but doesn't throw out right before though.

@marandaneto
Copy link
Contributor

LGTM 馃憤 Just one idea maybe - not sure if it'd make sense to introduce another method overload, which accepts a boolean like autoClose? Probably not needed though

I think that this is actually needed, since the streams will be open or will wait to be GCed, we could rather make it closable by default, and the StdoutTransport transport pass true to this param when calling the serialize method.

@romtsn
Copy link
Member

romtsn commented May 11, 2022

I've checked the usages of this method - basically everywhere we use try-with-resources around it, so we are safe internally. But yeah, if we expose this to the consumers, this may come as a surprise.

@adinauer
Copy link
Member Author

We also don't have an option to close the writer that is passed into public <T> void serialize(@NotNull T entity, @NotNull Writer writer) throws IOException {.

Also the NoOpSerializer would then also have to close the stream to be consistend and not leave peoples streams open despite them telling us to close via the boolean you suggested.

@adinauer
Copy link
Member Author

@marandaneto @romtsn do you still want me to implement a flag for autoClose after my explanation above?

@romtsn
Copy link
Member

romtsn commented May 13, 2022

I'm good without it, since the writer overload does not close by default already anyway, so we're just aligning here kinda. Internally we're closing it everywhere, so we're good. For the consumers - I hope the javadoc is enough

@adinauer adinauer merged commit ad91a62 into 6.x.x May 17, 2022
@adinauer adinauer deleted the fix/do-not-close-stream-in-json-serializer branch May 17, 2022 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants