Skip to content

fix: #6819 handle invalid toml file#7548

Merged
nhumblot merged 2 commits intomainfrom
6819-handle-invalid-toml-file-without-failing-build
Mar 26, 2025
Merged

fix: #6819 handle invalid toml file#7548
nhumblot merged 2 commits intomainfrom
6819-handle-invalid-toml-file-without-failing-build

Conversation

@nhumblot
Copy link
Copy Markdown
Collaborator

@nhumblot nhumblot commented Mar 24, 2025

Description of Change

The goal of this PR is to handle an unparsable toml file in case it does not respect the toml specification. As of now, the analysis fail in error when such a file is present.

This changes aims to provide a warning message telling the user the file could not be parsed and is therefore excluded from the analysis. The stack trace can be visible when debug logs are enabled.

Please note this PR also remove a copyright mention in both modified files, as advised by the Apache foundation.

Comments are welcomed!

Current behavior

[WARN] An unexpected error occurred during analysis of '/home/jtorres/experiments/base/demo-project/node_modules/node-gyp/gyp/pyproject.toml' (Poetry Analyzer): java.lang.IllegalStateException: Invalid key on line 41: lint.select
[ERROR]
java.lang.RuntimeException: java.lang.IllegalStateException: Invalid key on line 41: lint.select
        at com.moandjiezana.toml.Toml.read(Toml.java:74)
        at org.owasp.dependencycheck.analyzer.PoetryAnalyzer.analyzeDependency(PoetryAnalyzer.java:150)
        at org.owasp.dependencycheck.analyzer.AbstractAnalyzer.analyze(AbstractAnalyzer.java:131)
        at org.owasp.dependencycheck.AnalysisTask.call(AnalysisTask.java:88)
        at org.owasp.dependencycheck.AnalysisTask.call(AnalysisTask.java:37)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.IllegalStateException: Invalid key on line 41: lint.select
        at com.moandjiezana.toml.Toml.read(Toml.java:140)
        at com.moandjiezana.toml.Toml.read(Toml.java:107)
        at com.moandjiezana.toml.Toml.read(Toml.java:72)
        ... 8 common frames omitted

Behavior introduced by this change

[DEBUG] Invalid toml file, cannot parse '/home/nhumblot/dev/wkspace/DependencyCheck/core/target/test-classes/node-gyp-toml/pyproject.toml'
java.lang.RuntimeException: java.lang.IllegalStateException: Invalid key on line 41: lint.select
	at com.moandjiezana.toml.Toml.read(Toml.java:74)
	at org.owasp.dependencycheck.analyzer.PoetryAnalyzer.parseDependencyFile(PoetryAnalyzer.java:212)
	at org.owasp.dependencycheck.analyzer.PoetryAnalyzer.analyzeDependency(PoetryAnalyzer.java:152)
	at org.owasp.dependencycheck.analyzer.AbstractAnalyzer.analyze(AbstractAnalyzer.java:131)
	at org.owasp.dependencycheck.analyzer.PoetryAnalyzerTest.testNodeGypToml(PoetryAnalyzerTest.java:87)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.IllegalStateException: Invalid key on line 41: lint.select
	at com.moandjiezana.toml.Toml.read(Toml.java:140)
	at com.moandjiezana.toml.Toml.read(Toml.java:107)
	at com.moandjiezana.toml.Toml.read(Toml.java:72)
	... 34 common frames omitted
[WARN] toml file skipped: /home/nhumblot/dev/wkspace/DependencyCheck/core/target/test-classes/node-gyp-toml/pyproject.toml could not be parsed

Related issues

Fixes #6819

Have test cases been added to cover the new functionality?

yes

@boring-cyborg boring-cyborg bot added core changes to core tests test cases labels Mar 24, 2025
@nhumblot nhumblot merged commit 363dca3 into main Mar 26, 2025
7 checks passed
@nhumblot nhumblot deleted the 6819-handle-invalid-toml-file-without-failing-build branch March 26, 2025 06:43
@nhumblot nhumblot added this to the 12.1.1 milestone Mar 26, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

core changes to core tests test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error Analyzing Angular App + node-gyp dependency

2 participants