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

Remove static cache for generated names in SimpleNameFactory #149

Merged
merged 2 commits into from
Apr 26, 2021

Conversation

bigdaz
Copy link
Contributor

@bigdaz bigdaz commented Apr 25, 2021

The SimpleNameFactory was using a static List in an attempt to improve performance,
by avoiding the need to recreate the String name multiple times. The implementation
was not thread-safe, and could result in invalid names being produced when Proguard
was being run concurrently within the same classloader.

When 2 threads entered getName() simultaneously, they could both construct the same
name value for the same index, and both would then add these names to the static Map.
This resulted in a name List like `['a', 'a', 'c', ...].

This bug would manifest itself with a Duplicate Jar Entry exception, due to the fact
that SimpleNameFactory would return the same name value on subsequent calls.
This fact was verified by logging the names produced by SimpleNameFactory.

This commit merely removes the questionable optimization. If name generation is demonstrated
to be a performance bottleneck a safer optimization should be implemented, ensuring
correct synchronization on shared resources.

bigdaz and others added 2 commits April 25, 2021 11:33
The `SimpleNameFactory` was using a static List in an attempt to improve performance,
by avoiding the need to recreate the String name multiple times. The implementation
was not thread-safe, and could result in invalid names being produced when Proguard
was being run concurrently within the same classloader.

When 2 threads entered `getName()` simultaneously, they could both construct the same
name value for the same index, and both would then add these names to the static Map.
This resulted in a name List like `['a', 'a', 'c', ...].

This bug would manifest itself with a `Duplicate Jar Entry` exception, due to the fact
that `SimpleNameFactory` would return the same name value on subsequent calls.

This commit merely removes the optimization. If name generation is demonstated to be
a performance bottleneck, and safer optimization should be implemented, ensuring
correct synchronization on shared resources.
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@mrjameshamilton mrjameshamilton merged commit 3db8163 into Guardsquare:master Apr 26, 2021
@bigdaz bigdaz deleted the duplicate-jar-entry branch April 26, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants