-
Notifications
You must be signed in to change notification settings - Fork 80
fix(pip native inspector): Prevent NPE when no project name can be derived IDETECT-4923 #1621
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
Conversation
…rived IDETECT-4923
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
This PR adds defensive exception handling to prevent NullPointerExceptions when attempting to derive a project name from pyproject.toml or setup.py files. The fix wraps the TOML parsing and setup.py execution logic in try-catch blocks and adds null checks to guard against NPE conditions.
Key Changes:
- Added null checks for
tomlParseResult.getTable(PROJECT_KEY)andprojectTablebefore accessing them - Wrapped TOML parsing logic in a try-catch block with debug logging
- Wrapped setup.py execution logic in a try-catch block with debug logging
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } catch (Exception e) { | ||
| logger.debug("Failed to parse project name from pyproject.toml."); |
Copilot
AI
Jan 6, 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.
The error message should include the exception details to aid debugging. Consider logging the exception message or using logger.debug with the exception parameter: logger.debug(\"Failed to parse project name from pyproject.toml.\", e)
| } catch (Exception e) { | ||
| logger.debug("Failed to parse project name from setup.py."); |
Copilot
AI
Jan 6, 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.
The error message should include the exception details to aid debugging. Consider logging the exception message or using logger.debug with the exception parameter: logger.debug(\"Failed to parse project name from setup.py.\", e)
| if (executableOutput.getReturnCode() == 0) { | ||
| List<String> output = executableOutput.getStandardOutputAsList(); | ||
| projectName = output.get(output.size() - 1).replace('_', '-').trim(); | ||
| } catch (Exception e) { |
Copilot
AI
Jan 6, 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.
Catching generic Exception is overly broad. Consider catching more specific exception types (e.g., NullPointerException, TomlParseException) to avoid masking unexpected errors that should be handled differently or propagated.
| projectName = output.get(output.size() - 1).replace('_', '-').trim(); | ||
| } | ||
| } | ||
| } catch (Exception e) { |
Copilot
AI
Jan 6, 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.
Catching generic Exception is overly broad. Consider catching more specific exception types (e.g., ExecutableRunnerException, IOException) to avoid masking unexpected errors that should be handled differently or propagated.
| } catch (Exception e) { | |
| } catch (ExecutableRunnerException e) { |
The toml parsing section can throw NPE at more than one step, so added try/catch and more generic handling of exceptions during attempts to derive project name.