Avoid NPE when compilation unit is missing#4854
Avoid NPE when compilation unit is missing#4854MeherSru wants to merge 1 commit intoeclipse-jdt:masterfrom
Conversation
|
@MeherSru : thanks for your contribution. Also please describe your problem & provide steps to reproduce. |
|
@iloveeclipse : I’ve signed the ECA. This change adds a defensive null check since TypeDeclaration.getCompilationUnitDeclaration() can return null. Without the check, dereferencing compUnitDecl.currentPackage could lead to a potential NullPointerException in edge or recovery scenarios. |
It seems your email uses current IP address received via DHCP, and that will probably change in the future, so probably not a good choice for a long term. Anyway, let wait for the ECA database update, I believe it needs some hours.
Can you provide steps to reproduce or exception stack? |
|
Hi Andrey @iloveeclipse There's no real stack trace for this. I was mucking around with the javac version of jdt, as well as a mixed environment where I was using some of ecj and some of javac. I just happened to notice that this particular call wasn't null-protected, while other calls to getCompilationUnitDeclaration() were null-protected. See: CompilationUnitResolver, BindingKeyResolver, and ProblemHandler. |
Sure, it is clear why the NP check is needed, but the main reason I'm asking is to understand the root cause of NPE (as it was reported as NPE, see PR title). So far NPE at this place was not reported, and if you observed it, we've missed some use case and that use case then deserves a regression test. @stephan-herrmann : the code deals with null annotations, so you may want to look into. |
|
To be more clear, there was no root cause, as there was no bug experienced in a running environment. This was source code level analysis / observation, and a PR created simply to align with other callers of the same method, who all performed null checks. |
|
Any chance we can get this merged? Or is source-code level analysis insufficient to get an NPE check added? |
Would be OK from my POV, but ...
Whatever you did is not OK. Please check your mail linked to your eclipse.org account and the one you've used to sign ECA. They should be identical. |
|
Hi @iloveeclipse, Thanks for checking. At the time I created this PR, I had not yet signed the ECA. I signed it afterward using the same email address linked to my Eclipse account and Git commits. I have not opened a new PR for this change. |
I currently don't have time nor energy for an extended discussion, but since you asked these are my comments:
It's all not a huge deal because neither |
What it does
How to test
Author checklist