-
Notifications
You must be signed in to change notification settings - Fork 1
fix(inlay): prevent NPE in parameter hint scoring #1045
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
base: main
Are you sure you want to change the base?
Conversation
Safely handle null argument types by skipping them instead of using ./gradlew :gls:detekt operator. Addresses potential crashes in InlayHintsProvider when type resolution fails for an argument.
Summary of ChangesHello @albertocavalcante, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a potential Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughA single file modification improves null-safety handling in the InlayHints scoring logic by replacing unsafe argument type assertions with explicit null and unknown type checks using conditional expressions. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Code Review
This pull request addresses a potential null pointer exception in the parameter hint scoring logic by refactoring argument type validation to be more robust and idiomatic using takeUnless and the elvis operator, thereby removing a non-null assertion (!!). While the NPE is resolved, a security audit identified an inconsistency in type name validation before being passed to the class loader. Specifically, the functions resolveClass and findGdkMethodCandidates lack validation guards, which could allow malformed strings from the AST to reach sensitive class-loading sinks. It is recommended to apply consistent validation using TypeStringUtils.isValidClasspathTypeName to improve the robustness and security of the provider.
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.
Pull request overview
Adjusts inlay-hint parameter candidate scoring to avoid potential null dereferences when argument type inference fails.
Changes:
- Skip scoring for arguments whose inferred type is
nullor considered “unknown”. - Remove unsafe
!!usage when passing argument types intomatchScore.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| argumentTypes.forEachIndexed { index, argType -> | ||
| if (isUnknownType(argType)) { | ||
| return@forEachIndexed | ||
| } | ||
| // Skip null or unknown types | ||
| val nonNullArgType = argType?.takeUnless { isUnknownType(it) } ?: return@forEachIndexed | ||
| val paramType = candidate.parameterTypes.getOrNull(index) ?: return -1 | ||
| val matchScore = matchScore(paramType, argType!!, compilationService) | ||
| val matchScore = matchScore(paramType, nonNullArgType, compilationService) |
Copilot
AI
Jan 30, 2026
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.
Add a regression test covering the case where at least one entry in argumentTypes is null (e.g., SemanticTypeResolver.resolveType fails for one argument) while other arguments have known types, to ensure candidate scoring does not throw and still resolves the correct overload/parameter names. There are already comprehensive InlayHintsProviderTest/parameter hint tests, so this scenario should be easy to add and will prevent the NPE from reappearing.
|


Summary
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.