Skip to content

[IO-826] Add runtime exception support to broken streams#530

Merged
garydgregory merged 16 commits into
apache:masterfrom
markslater:add-runtime-exception-support-to-broken-streams-erase-implementation
Dec 21, 2023
Merged

[IO-826] Add runtime exception support to broken streams#530
garydgregory merged 16 commits into
apache:masterfrom
markslater:add-runtime-exception-support-to-broken-streams-erase-implementation

Conversation

@markslater

@markslater markslater commented Dec 20, 2023

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/IO-826

As discussed in #528.

One point to note: Is there a reason to keep the deprecated constructors such as BrokenInputStream(final IOException exception)? Given that the new constructors such as BrokenInputStream(final Throwable exception) accept a superclass of IOException, it seems the old constructor could be removed without a breaking change.

@garydgregory

Copy link
Copy Markdown
Member

While this may not break source compatibility, it would break binary compatibility per https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.4.12 (at least how I read it and how japicmp sees it).

@markslater

Copy link
Copy Markdown
Contributor Author

Yes, you're absolutely right. I hadn't thought of that.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@markslater
TY for your update.
See my few comments.

*/
@Override
public synchronized void reset() throws IOException {
public void reset() throws IOException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keep synchronized, there is no reason to break the superclass' specification here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify? I can't see any mention of synchronized in the javadoc.

@garydgregory garydgregory Dec 20, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uh? Javadoc doesn't document synchronized keywords. Same for native, see https://docs.oracle.com/en/java/javase/11/javadoc/javadoc-command.html#GUID-B0079316-8AA3-475B-8276-6A4095B5186A

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't explain myself very well. I meant to say I don't see any mention of locking in the javadoc.

I dug a bit deeper and it seems the synchronization of the reset method varies by JDK. Here's a summary of which JDKs mark it as synchronized, sampled from the ones I had to hand:

java.io.InputStream#reset java.io.Reader#reset
openjdk-7
corretto-1.8.0_392
temurin-11.0.21
corretto-20.0.2.10
coretto-21.0.1.12

AFAIK java.io.Reader#reset has never been synchronized, so that one is easy. For java.io.InputStream#reset, I guess it should be synchronized to line up with Java 8, since that's the library's targeted version?

@garydgregory garydgregory Dec 21, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, this PR is about a new feature and should not flip-flop an unrelated implementation detail IMO. Especially when the setting seems to change between vendo and version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, I see synchronized on InputStream Temurin 17 but not Temurin 21.

Comment thread src/main/java/org/apache/commons/io/input/BrokenInputStream.java Outdated
Comment thread src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java Outdated
Comment thread src/test/java/org/apache/commons/io/input/BrokenReaderTest.java Outdated
* Throws the configured exception.
*
* @throws IOException always thrown
* @throws IOException always throws the exception configured in the constructor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since there is more than one constructor, I think we should say "in a constructor", not in "in the...".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As you like - I read this as 'in the constructor [you callled]', but I don't have a strong feeling either way.

@markslater markslater Dec 20, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How about "always throws the exception configured on construction"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about "always throws the exception configured on construction"?

I'm not going to go round and round on such a small point. I'll likely review post merge and resolve whatever is left.

@codecov-commenter

codecov-commenter commented Dec 20, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (6b0ed87) 86.17% compared to head (20f379d) 86.01%.
Report is 6 commits behind head on master.

❗ Current head 20f379d differs from pull request most recent head d54985b. Consider uploading reports for the commit d54985b to get more accurate results

Files Patch % Lines
...java/org/apache/commons/io/input/BrokenReader.java 30.00% 7 Missing ⚠️
...g/apache/commons/io/output/BrokenOutputStream.java 42.85% 4 Missing ⚠️
...ava/org/apache/commons/io/output/BrokenWriter.java 42.85% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #530      +/-   ##
============================================
- Coverage     86.17%   86.01%   -0.17%     
+ Complexity     3433     3418      -15     
============================================
  Files           229      229              
  Lines          8162     8167       +5     
  Branches        959      959              
============================================
- Hits           7034     7025       -9     
- Misses          845      860      +15     
+ Partials        283      282       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@garydgregory garydgregory merged commit dd63fa3 into apache:master Dec 21, 2023
@garydgregory garydgregory changed the title [IO-826] Reimplemented add runtime exception support to broken streams [IO-826] Add runtime exception support to broken streams Dec 21, 2023
asfgit pushed a commit that referenced this pull request Dec 21, 2023
- Add BrokenReader.BrokenReader(Throwable)
- Add BrokenOutputStream.BrokenOutputStream
- Add BrokenWriter.BrokenWriter(Throwable)
asfgit pushed a commit that referenced this pull request Dec 21, 2023
asfgit pushed a commit that referenced this pull request Dec 21, 2023
@garydgregory

Copy link
Copy Markdown
Member

@markslater PR merged, TY!

@markslater markslater deleted the add-runtime-exception-support-to-broken-streams-erase-implementation branch December 21, 2023 17:41
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.

3 participants