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 ConfigUtil#getString ConcurrentModificationException #6841

Merged
merged 7 commits into from
Nov 1, 2024

Conversation

jack-berg
Copy link
Member

Resolves #6732.

Builds on #6746.


@Test
@SuppressWarnings("ReturnValueIgnored")
void systemPropertiesConcurrentAccess() throws ExecutionException, InterruptedException {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test fails on java 8 if you call System.getProperties() instead of ConfigUtil#safeSystemProperties().

* of exception. See https://github.com/open-telemetry/opentelemetry-java/issues/6732 for details.
*/
public static Properties safeSystemProperties() {
return (Properties) System.getProperties().clone();
Copy link
Member Author

Choose a reason for hiding this comment

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

Cloning seems to be the simplest way to accommodate various use cases. Anything other option that returns Properties ends up mimicking the logic of clone() anyway. If clone() ends up being too expensive (I doubt it), we can cache a copy.

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with it

ConfigUtil.getString(..) is already slow (too slow to be used on the hotpath) since it normalizes all the entry keys on each call

Copy link
Contributor

Choose a reason for hiding this comment

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

If clone() ends up being too expensive

clone is only needed on jdk8 and android so we could skip it on other jdks if we so wish. Untested code follows

private static final CLONE_PROPERTIES = System.getProperty("java.version").equals("0") // android
  || System.getProperty("java.specification.version").startsWith("1."); // jdk8

Copy link
Member Author

Choose a reason for hiding this comment

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

clone is only needed on jdk8 and android so we could skip it on other jdks if we so wish.

That's true. I'd prefer to keep that in our back pocket in case we need it. As a general rule, I think we avoid runtime-specific code unless we have a strong reason (subjective definition of "strong").

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.48%. Comparing base (697b4e0) to head (08d09ea).
Report is 61 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6841      +/-   ##
============================================
+ Coverage     90.08%   90.48%   +0.40%     
- Complexity     6464     6598     +134     
============================================
  Files           718      731      +13     
  Lines         19528    19737     +209     
  Branches       1923     1938      +15     
============================================
+ Hits          17591    17859     +268     
+ Misses         1348     1285      -63     
- Partials        589      593       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* of exception. See https://github.com/open-telemetry/opentelemetry-java/issues/6732 for details.
*/
public static Properties safeSystemProperties() {
return (Properties) System.getProperties().clone();
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with it

ConfigUtil.getString(..) is already slow (too slow to be used on the hotpath) since it normalizes all the entry keys on each call

@jack-berg jack-berg merged commit d9fce84 into open-telemetry:main Nov 1, 2024
20 checks passed
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.

ConcurrentModificationException in ConfigUtil
4 participants