-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Exclude from a report a part of bytecode that compiler generates for a try-with-resources #500
Conversation
@Godin Count me deeply impressed!!! And I'm very sorry that I couldn't immediately jump into both PRs. So+Mo are travel dates, so I hope to study it in detail then. |
@marchof no worry, will be cool to get all this on board, but no need to rush - let's do a proper careful review and testing. Slowly, but at least we are progressing on this big subject. And I personally start to see the light at the end of the tunnel, which wasn't the case few months ago. FYI next week I'm also kind of traveling - will attend DevoxxUS, and hope to not be offline all the time. |
@Godin It would be useful if the members of |
@bjkail Hey, glad to see you here! Actually was about to ask if you're interested in this subject and if so maybe you could leave some valuable comments as before 😉 And here they are 😋 You are right on all points - let's cleanup and harden this PoC. Also wondering WDTY about approach in general? About it we'd better add explanatory comments also. As well as estimate impact on performance of analysis - can imagine some optimizations... but traded them on the correctness and attempt to keep relative simplicity of code for now. Anyway thank you! we really appreciate your help 👍 |
@Godin The overall approach seems reasonable to me of skipping ignored instructions in Last time I thought about t-w-r, I was thinking to require the t-w-r close sequence be replicated at the end of the try block and each catch block (including Throwable) to ensure it was either written by a compiler or fully correctly hand-written. My motivation was to avoid filtering out a badly hand-written close sequence (e.g., at the end of try block only but not all catch blocks or missing Throwable block, etc.), but the algorithm to do the rigid matching seemed quite complex, especially for custom finally blocks and nested t-w-r (thus my suggested testcases). However, I am now thinking your approach is fine. There is some risk of false positive (matching a hand-written close sequence), but the risk is low since the close sequence is relatively complex, and we can leave detecting badly hand-written close sequences (like missing close sequence on some possible code path) to static analyzers like FindBugs. |
As an anecdote, last time I investigated t-w-r was because we kept regressing coverage in classes that use t-w-r heavily because drops go unnoticed due to all the uncovered generated code. I tried forcing all the generate code paths to be executed (our code/tests made it easy to force all the conditions: null resource, exception with null resource, exception with non-null resource, close exception, exception and close exception), but I ultimately gave up when I discovered javac emits completely dead code:
So, I think this will be a great feature to have in JaCoCo :-). |
50d98bc
to
1adc2d1
Compare
* initialized using <code>new</code></li> | ||
* <li>synthetic method <code>$closeResource</code> containing | ||
* <code>null</code> check of primaryExc and calls to methods | ||
* <code>addSuppressed</code> and <code>close</code> is used when numbers of |
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.
typo - numbers
instead of number
@marchof I scanned bigger subset of Maven Central - latest versions of some artifacts within group Nevertheless 9753 try-with-resources statements were filtered correctly from ≈20 Gb of JAR files with classes. And this time ECJ filter was triggered quite a good amount of times. Case that was already presented in our tests and not filtered - when body of try-with-resources is empty
was encountered in
Another funny case that was already presented in our tests and not filtered - when try-with-resources contains only
was encountered in
Not explicitly presented in out tests, but a kind of variation of previous and not filtered - when there is no non-exceptional path from a body as for example
was encountered in
An interesting case where source code contains try-with-resources, but retrolambda removes call to
An interesting case where AspectJ adds try-with-resources into bytecode was encountered in
All in all: I satisfied by results and would like to merge this PR. We can deal with cases of an empty body and absence of non-exceptional path in a separate PR. If you agree I'll squash and merge into master. |
@Godin Awesome work, Evgeny! I'm absolutly curious about the exact test setup. And yes, we can add corner cases later. I was already about to ask about the performance of the new, way more readable matching code. As there is no negative impact -> yes, please merge this! |
@Godin , when do you plan to release this ? |
@romani please see already existing answers on such question: |
https://github.com/jacoco/jacoco/wiki/filtering-JAVAC.TRYWITH