api: Add a Supplier overload to Context - #12935
Conversation
|
|
#12936 Appears to be needed. |
| assertSame(current, Context.current()); | ||
|
|
||
| final TestError err = new TestError(); | ||
| try { |
There was a problem hiding this comment.
TestError caught = assertThrows(TestError.class, ...
There was a problem hiding this comment.
If you feel strongly I can, but I was keeping the style of the tests around it.
There was a problem hiding this comment.
assertThrows() was not available back then, worth using in new code
|
@kannanjgithub @ejona86 Looks like context is Java7? Any chance Line 19 in 3b3002c |
ejona86
left a comment
There was a problem hiding this comment.
supply() is a bit of a weird name. But get() would be even weirder.
Mark it experimental like normal? (Just with a comment, since we can't use the annotation here.)
Yeah, I think we could drop Java 7 and compile with Java 8. It's been 4.5 years since we dropped Java 7. We should probably keep the separate compilation step as when we drop Java 8 we'll probably want Context to again stay on Java 8 for a while.
| * @param supplier {@link Supplier} to use to produce the value. | ||
| * @return result of supplier. | ||
| */ | ||
| @CanIgnoreReturnValue |
There was a problem hiding this comment.
This seems a bit strange. Did we only ignore call() because of existing callers? Hey, look! @carl-mastrangelo reviewed #4430 😛
I guess people could be doing Callable<Void> if they wanted a Runnable that could throw exceptions. I don't think there's any point to ignoring a Supplier's return value though.
There was a problem hiding this comment.
Actually, Callable<Void> shouldn't even need @CanIgnoreReturnValue. So I guess we did it just because there were existing callers.
There was a problem hiding this comment.
Definitely don't like the name supply, but also can't really use an overload of call. I'm open to alternatives. invoke() ? callInContext() ? apply() ?
There was a problem hiding this comment.
Also I sent out #12955 to update the context version
Fixes #12927