Skip to content
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

fix: issue 5452 - ConcurrentModificationException in NodePackageAnalyzer.processDependencies - adding synchronized block #6501

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

dabal
Copy link
Contributor

@dabal dabal commented Mar 3, 2024

Fixes Issue

#5452 - ConcurrentModificationException in NodePackageAnalyzer.processDependencies

Description of Change

Surrounding merging dependency code in synchronized block. I was facing the issue when I had multiple json files added - by /tmp/*/package-lock.json. Most of them contains the same set of dependencies. I've noticed that this issue doesn't exist when I change the number of threads in org/owasp/dependencycheck/Engine.java:811 to 1. This would mean that this is ordinary concurrency issue. I've checked if it occurs if I add the synchronized to the org.owasp.dependencycheck.analyzer.DependencyMergingAnalyzer#mergeDependencies but the issue was still there. And I've noticed that the when one thread is throwing this exeption, the other one is trying to do org.owasp.dependencycheck.Engine#removeDependency.

This is why I've added the synchronized block to thos part of the method

 synchronized (this) {
                    final Dependency existing = findDependency(engine, name, version);
                    if (existing != null) {
                        if (existing.isVirtual()) {
                            DependencyMergingAnalyzer.mergeDependencies(child, existing, null);
                            engine.removeDependency(existing);
                            engine.addDependency(child);
                        } else {
                            DependencyBundlingAnalyzer.mergeDependencies(existing, child, null);
                        }
                    } else {
                        engine.addDependency(child);
                    }
                }

After this I don't see anymore the ConcurrentModificationException

Have test cases been added to cover the new functionality?

no

@boring-cyborg boring-cyborg bot added the core changes to core label Mar 3, 2024
@dabal dabal changed the title issue 5452 - ConcurrentModificationException in NodePackageAnalyzer.processDependencies - adding synchronized block fix: issue 5452 - ConcurrentModificationException in NodePackageAnalyzer.processDependencies - adding synchronized block Mar 3, 2024
Copy link
Owner

@jeremylong jeremylong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeremylong jeremylong added this to the 9.0.10 milestone Mar 4, 2024
@jeremylong
Copy link
Owner

Thank you for the PR!

@dabal
Copy link
Contributor Author

dabal commented Mar 4, 2024

Thank you for the PR!

You are welcome:). Do I have to do anything more to get this merged? And I have a question about the time frame - when you would like to release the 9.0.10?

@jeremylong
Copy link
Owner

Again - thank you for the PR. I will try to release 9.0.10 within a week. I've been tied up with a lot of other non-OSS projects lately.

@jeremylong jeremylong merged commit 44a3f16 into jeremylong:main Mar 5, 2024
6 of 7 checks passed
lucas-kern pushed a commit to lucas-kern/DependencyCheck that referenced this pull request Mar 7, 2024
…zer.processDependencies - adding synchronized block (jeremylong#6501)

Co-authored-by: Grzegorz Dabrowski <grzegorz.dabrowski@hypr.com>

fix: set forceUpdate flag for empty hosted suppression file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core changes to core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants