-
Notifications
You must be signed in to change notification settings - Fork 163
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
Wrapped the OperationCanceledException in InterruptedException #1364
Conversation
0a06afd
to
ffaab8b
Compare
I'm not sure this is a generally and universally necessary change. In any case, please don't merge in commits to your PR. Keep the PR with a single commit and rebase on master when necessary. The PR in this state current cannot be properly reviewed or processed... |
That's better. 😄 Are such changes generally wanted? |
I think this kind of change makes sense, as there are several points in the code at which As far as I know, the first kind of change improving this exception handling was d8c2f86 Do you see any negative impact in these changes, @merks? |
I don’t see anything harmful. It’s just annoying (very verbose) that there is no convenient constructor. Which begs the question why there is no such constructor? Is it an unusual pattern to throw this type of exception as being caused by something else? Might we encapsulate the conversation somewhere? E.g., a toInterruptedException method on OperationCanceledException? |
First: You are right, the repetition is verbose and error prone and we should choose some better solution. This kind of exception wrapping seems to exist for a long time and I do not completely understand why. The obvious thing is that To avoid the repetition, I would propose the following: add some wrapping method to the |
Yes I would be much happier to see a concise, single-line replacement. The rethrow method is interesting but the compiler won’t know that flow will not continue as it knows when there is an explicit throw statement |
That's right. But if the wrap method returns an exception one can just write |
Exactly. That is why I think a method that returns the wrapping exception would be ideal. |
The answer is simple, because this exception is actually not to be created by user code except you have cleared the interrupted flag(!) so it can never be really "caused" by something see:
Nothing of those is happening here! Sadly InterruptedException is misuses at several places in eclipse while the proper one to use would be CancellationException but also in this case there is no causing exception because this can't be caused by another exception, in such case one has to use ExecutionException a good example is the method get(long timeout, TimeUnit) unit) of future task
I would avoid / replace this entirely instead of making it more convenient to follow this wrong pattern. |
I agree that no new code should follow this pattern, but we cannot easily change existing code either, as in some cases it affects public API (the Also note that this misused exception is only passed outside internal code rather rarely. If I remember correctly we now have around 5 places touched in Platform and Platform UI code.
It's correct that these exception would fit better, but please also note that they have been introduced into Java after at least some of this Eclipse code has been written initially. |
bundles/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java
Outdated
Show resolved
Hide resolved
But even before it was wrong to use that and eclipse has |
I totally agree with you :-) I just tried to understand (and partly justify) the decision made long years ago. But, anyway, we cannot change that anymore, so my primary goals would be to (1) avoid that this kind of misuse is repeated in new code and (2) that we make the best of the existing code in terms of providing information about the wrapped exception in case it is provided to non-internal code. |
978ff47
to
5ef1d72
Compare
@amartya4256 can you please rebase on master instead of merging master into this PR? |
@@ -435,7 +435,9 @@ private static void runInCurrentThread(IRunnableWithProgress runnable, IProgress | |||
runnable.run(progressMonitor); | |||
} | |||
} catch (OperationCanceledException e) { | |||
throw new InterruptedException(); | |||
InterruptedException interruptedException = new InterruptedException(e.getLocalizedMessage()); |
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.
I miss a systematic approach here. In the same file org.eclipse.jface.operation.ModalContext.run(IRunnableWithProgress, boolean, IProgressMonitor, Display)
also created an InterruptedException. Why isn't that code path updated?
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.
That code path was already updated some weeks ago to add the causing exception (the OperationCanceledException
) to the InterruptedException
. The systematics in this PR is that we went through all the Platform UI code to see where this pattern of misuse of InterruptedException
happened as well (and was not "improved" yet). The place touched here is the only remaining one we found.
We already discussed systematic ways of wrapping the OperationCanceledException
in this PR, but since we agree that this pattern is just legacy and should not be implemented anywhere else, I agree with @laeubi (#1364 (comment)) that we should not make this pattern more convenient to implement.
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.
Oh, my bad. I was looking at a different local version of that file.
eclipse-platform/eclipse.platform#853
Wrapped the OperationCanceledException in InterruptedException