-
Notifications
You must be signed in to change notification settings - Fork 414
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
OAK-11571: commons: add Closer class (similar to Guava Closer) #2181
base: trunk
Are you sure you want to change the base?
Conversation
…replacement and switch tests to new class
Commit-Check ✔️ |
…Closeable interface to Closer and test it
…) - add Closeable interface to Closer and test it" This reverts commit 5912f06.
…Closeable interface to Closer and test it
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pio/Closer.java
Outdated
Show resolved
Hide resolved
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pio/Closer.java
Show resolved
Hide resolved
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/pio/Closer.java
Outdated
Show resolved
Hide resolved
I believe all comments were based on misunderstandings about what Guava does; see again d254e8f which has the same tests running with Guava. @thomasmueller - every time we instantiate a collection with a non-default size, readers of the code will ask themselves: why? and does it really matter here? |
Things IMHO left to do:
Note that once this is in (and used throughout); we can get rid of the entire Guava common.io package. |
… Sonar happier wrt naming conventions
…row() just silences the close() method
toThrow = exception; | ||
} | ||
} | ||
} |
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.
What about RuntimeExceptions (or any Throwable that is not an IOException)? If they are thrown from closeable.close(), they will not be catched, even if suppressExceptionsOnClose is true (see modified test in comment below).
fail("should not throw but got: " + e); | ||
} | ||
} | ||
} |
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.
public void compareClosers() {
// when rethrow was called, Exceptions that happened upon close will be swallowed
com.google.common.io.Closer guavaCloser = com.google.common.io.Closer.create();
Closer oakCloser = Closer.create();
try {
throw oakCloser.rethrow(new InterruptedException());
} catch (Exception e) {}
try {
throw guavaCloser.rethrow(new InterruptedException());
} catch (Exception e) {}
try {
oakCloser.register(() -> { throw new RuntimeException(); });
oakCloser.close();
} catch (Exception e) {
fail("should not throw but got: " + e);
}
try {
guavaCloser.register(() -> { throw new RuntimeException(); });
guavaCloser.close();
} catch (Exception e) {
fail("should not throw but got: " + e);
}
}
would currently fail.
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.
RuntimeException are not yet treated correctly, see inline comments.
…e unchecked exceptions thrown by Closeables when rethrow was called
|
Note
1b60437
which added tests for Guava Closer. The Oak implementation only was written after tests were there.