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
Adds null check before calling nullable repository variable method to avoid NPE #6682 #6694
Adds null check before calling nullable repository variable method to avoid NPE #6682 #6694
Conversation
…riable to avoid NPE
@snreinert thanks for looking into this!
|
|
if (!repository.isAnyProjectOpened()) { | ||
if (repository != null && !repository.isAnyProjectOpened()) { | ||
//if no project is open, java.base may not be indexed. Fallback on default queries: | ||
return null; | ||
} |
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.
comment might need adjustment to:
//if no project is open or the JDK is not modular, java.base may not be indexed. Fallback on default queries:
I assume repository is always null for openjdk 8 checkouts. cc @jlahoda
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.
For openjdk 8 (and maybe prior) checkouts, the repository is null so the comment inside that block wouldn't apply. Would non-modular JDKs ever have a non-null repository?
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.
IIRC this was an attempt to avoid unnecessary parsing from source when none of the OpenJDK project is open and hence not indexed. There's probably nothing better we could do for JDK 8.
on second thought, lets keep it as is targeting master - no need to rush anything. |
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.
Looks good, thanks!
if (!repository.isAnyProjectOpened()) { | ||
if (repository != null && !repository.isAnyProjectOpened()) { | ||
//if no project is open, java.base may not be indexed. Fallback on default queries: | ||
return null; | ||
} |
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.
IIRC this was an attempt to avoid unnecessary parsing from source when none of the OpenJDK project is open and hence not indexed. There's probably nothing better we could do for JDK 8.
merging this one too for NB21, congrats to your first contribution @snreinert! && thanks for review @lahodaj |
Fixes #6682. The repository value that is passed to the
ClassPathProviderImpl
constructor is null when the file that triggeredClassPathProviderImpl::findClassPath
is a Java source file in a JDK repo directory structure.