From d571f6abf971535646a53306e9ba057cd1d473fc Mon Sep 17 00:00:00 2001 From: shantyk Date: Wed, 10 Dec 2025 13:59:52 +0000 Subject: [PATCH 1/2] fix(pip native inspector): Prevent NPE when no project name can be derived IDETECT-4923 --- .../detectables/pip/inspector/PipInspectorExtractor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java b/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java index d0c0d31aa6..c5e507a11a 100644 --- a/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java +++ b/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java @@ -122,9 +122,12 @@ private String getProjectName(File directory, ExecutableTarget pythonExe, File s String projectName = providedProjectName; - if (tomlParseResult != null) { + // TODO this whole section with the toml parsing can throw NPEs at different points, add try/catch instead of ifs at each step before merging. + if (tomlParseResult != null && (tomlParseResult.getTable(PROJECT_KEY) != null)) { + logger.info("The value of the condition is: " + (tomlParseResult != null && (tomlParseResult.getTable(PROJECT_KEY) != null))); TomlTable projectTable = tomlParseResult.getTable(PROJECT_KEY); - if(projectTable.contains(NAME_KEY)) { + logger.info("Project table is: " + projectTable); + if( projectTable!= null && projectTable.contains(NAME_KEY)) { projectName = projectTable.getString(NAME_KEY); } } else if (setupFile != null && setupFile.exists()) { From 56fc05b2b6d844a65f4d714e020eafbf81e91f3b Mon Sep 17 00:00:00 2001 From: shantyk Date: Mon, 5 Jan 2026 06:58:37 -0700 Subject: [PATCH 2/2] Wrap in try/catch blocks --- .../pip/inspector/PipInspectorExtractor.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java b/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java index c5e507a11a..4cad06f7e1 100644 --- a/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java +++ b/detectable/src/main/java/com/blackduck/integration/detectable/detectables/pip/inspector/PipInspectorExtractor.java @@ -122,21 +122,30 @@ private String getProjectName(File directory, ExecutableTarget pythonExe, File s String projectName = providedProjectName; - // TODO this whole section with the toml parsing can throw NPEs at different points, add try/catch instead of ifs at each step before merging. - if (tomlParseResult != null && (tomlParseResult.getTable(PROJECT_KEY) != null)) { - logger.info("The value of the condition is: " + (tomlParseResult != null && (tomlParseResult.getTable(PROJECT_KEY) != null))); - TomlTable projectTable = tomlParseResult.getTable(PROJECT_KEY); - logger.info("Project table is: " + projectTable); - if( projectTable!= null && projectTable.contains(NAME_KEY)) { - projectName = projectTable.getString(NAME_KEY); + try { + if (tomlParseResult != null && (tomlParseResult.getTable(PROJECT_KEY) != null)) { + TomlTable projectTable = tomlParseResult.getTable(PROJECT_KEY); + if (projectTable != null && projectTable.contains(NAME_KEY)) { + projectName = projectTable.getString(NAME_KEY); + return projectName; + } } - } else if (setupFile != null && setupFile.exists()) { - List pythonArguments = Arrays.asList(setupFile.getAbsolutePath(), "--name"); - ExecutableOutput executableOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pythonExe, pythonArguments)); - if (executableOutput.getReturnCode() == 0) { - List output = executableOutput.getStandardOutputAsList(); - projectName = output.get(output.size() - 1).replace('_', '-').trim(); + } catch (Exception e) { + logger.debug("Failed to parse project name from pyproject.toml."); + } + + + try { + if (setupFile != null && setupFile.exists()) { + List pythonArguments = Arrays.asList(setupFile.getAbsolutePath(), "--name"); + ExecutableOutput executableOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pythonExe, pythonArguments)); + if (executableOutput.getReturnCode() == 0) { + List output = executableOutput.getStandardOutputAsList(); + projectName = output.get(output.size() - 1).replace('_', '-').trim(); + } } + } catch (Exception e) { + logger.debug("Failed to parse project name from setup.py."); } return projectName;