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

Return a copy instead of cached array #3163

Merged
merged 1 commit into from
Sep 13, 2021

Conversation

sdedic
Copy link
Member

@sdedic sdedic commented Sep 12, 2021

During some implementation I've mindlessly modified the result of ClassPath.getRoots() call ... and then spent more than 5 hours by hunting down the bug since it wasn't originally obvious, but "sometimes" the parser stopped to resolving symbols against the classpath. "sometimes" = when the added (debugging) code run and modified the ClassPath caches for all IDE.
I think making the code fool-proof is worth the array-copy overhead...

@sdedic sdedic self-assigned this Sep 12, 2021
@@ -241,7 +241,7 @@ public ClassPathImplementation getClassPathImpl(ClassPath cp) {
long current;
synchronized (this) {
if (rootsCache != null) {
return this.rootsCache;
return Arrays.copyOf(rootsCache, rootsCache.length);

Choose a reason for hiding this comment

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

I'd use this.rootsCache.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.

Good point; recommitted as 3fc65de. Thanks.

@sdedic sdedic merged commit 60d04ff into apache:master Sep 13, 2021
@ebarboni ebarboni added this to the 12.6 milestone Sep 15, 2021
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.

3 participants