-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Prevents potential NPE while closing resource #42007
Conversation
This prevents the `java.lang.NullPointerException: Cannot invoke "io.quarkus.bootstrap.runner.JarFileReference.close(io.quarkus.bootstrap.runner.JarResource)" because "ref" is null` error
I'd rather have @mariofusco look at this one since he has been working in this area lately. That said, the change does seem to make sense |
@gastaldi To be honest I put there that assertion exactly because I didn't expect that reference to be null and I wanted a fail fast mechanism in this case instead of hiding the dust under the carpet with a null check. @geoand @gsmet In essence if we're in a hurry it is ok for me to merge this pull request (at least as a temporary solution), but I'm afraid that this is fixing the symptom of the problem rather than its root cause and I will need to investigate it further regardless. I will try to reproduce the problem on my side (any hint on how to do this will be welcome) and I will keep you updated with my findings. |
@mariofusco the problem is that the A more conservative approach would be to revert #40942 and merge it back when we figure out what is causing that reference to be null |
That's why I wanted your input 😉 |
Fwiw I haven’t modified the runner CL. As for being in a hurry, if this code is in the 3.13 branch, I don’t feel comfortable pushing 3.13.0 with a possible NPE. So either we find the root cause by Tuesday evening or I would recommend to merge (and backport this). I’m on my phone so can’t easily check if this is in 3.13. |
Status for workflow
|
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 will merge this to get it in 3.13.0.
Please follow up on this when you have the time to investigate and add the backport label so that we push it to 3.13.
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 spent a few hours trying to reproduce this NPE, but with no luck. I understand that it could eventually be caused by a seldomly happening race condition, but I ran the test-suite of that rest-villains
project hundreds of times against the latest quarkus snapshot, from both the IDE and the CLI, and I've never seen it happening.
Meanwhile I tried to also reread and statically analyze my code going line by line, but I really don't see how that reference could be possibly null at that point. That CompletableFuture
is published as already completed, and once completed its value cannot be changed anymore, so either the AtomicReference
is empty (and there is a already a null check for that case) or it contains a future pointing to a JarResource
.
The only other possible alternative, and actually the only situation where that CompletableFuture
couldn't have a value, is when it is not possible at all to load the requested jarFile. This could maybe explain why I couldn't reproduce that problem locally, but even in this case I'd expect some other failure to happen far before reaching the close()
(like a ClassNotFoundException
), or at least to have that IOException
in the continuous integration log, but I don't see any track of it.
That said, I'm still unsure why this further null check could be necessary, but at this point I don't have anything against it. Sorry for taking some time, but I just want to be 100% sure that I wasn't overlooking anything in the implementation of the class loader.
Oh no worries, I didn't want to press you, quite the opposite actually. I merged it so that you have more time to figure it out if you needed to. Thanks for the investigation! |
@gsmet Thanks for merging this, bad timing on my side, I published my feedback in the moment you hit the merge button :) I did all possible investigations and as you can read in my former comment it's ok for me to merge this pull request even though I dind't find a reasonable explanation for that NPE, neither I've been able to reproduce it in any way. |
This prevents the following error from happening: