-
-
Notifications
You must be signed in to change notification settings - Fork 9k
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
IntelliJ/Java: Duplicate code -- Refactored as AntClassLoader.storeAndConvert(...Convert<T>) #4075
IntelliJ/Java: Duplicate code -- Refactored as AntClassLoader.storeAndConvert(...Convert<T>) #4075
Conversation
…dConvert(...Convert<T>)
25ff86f
to
5d0cc4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there was misguiding comment in the code
} else { | ||
return null; | ||
} | ||
//to eliminate a race condition, retrieve the entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this comment really represent the logic? it was there for one code part, but not for another one. For me it looks like there was missing TODO
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this code is how it tries to eliminate a race condition.
The simplest racing logic would be:
if (jarFile == null) {
if (file.exists()) {
jarFile = new JarFile(file);
jarFiles.put(file, jarFile);
} else {
return null;
}
// at this point, you'd expect `jarFile == (JarFile) jarFiles.get(file)`, but it might not if you win the race.
}
The correct thing to do is to lock something. Otherwise, even this code probably isn't good enough.
I think w/ this code and 3 threads we could still get a race:
Enter the if:
(1) T1 if (jarFile == null) {
(2) T2 if (jarFile == null) {
(3) T3 if (jarFile == null) {
Create a file:
(4) T1 jarFile = new JarFile(file);
(5) T2 jarFile = new JarFile(file);
(6) T3 jarFile = new JarFile(file);
Race time:
(7) T1 jarFiles.put(file, jarFile);
(8) T2 jarFiles.put(file, jarFile);
(9) T1 jarFile = (JarFile) jarFiles.get(file);
(10) T2 jarFile = (JarFile) jarFiles.get(file);
(11) T3 jarFiles.put(file, jarFile);
(12) T3 jarFile = (JarFile) jarFiles.get(file);
Check our winner's:
(13) T1 JarEntry entry = jarFile.getJarEntry(resourceName);
This is T2's jarFile from (5)/(8) -- retrieved at (9)
(14) T2 JarEntry entry = jarFile.getJarEntry(resourceName);
This is T2's jarFile from (5)/(8) -- stored at (8) and retrieved at (10)
(15) T3 JarEntry entry = jarFile.getJarEntry(resourceName);
This is T3's jarFile from (6) -- stored at (11) and retrieved at (12)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not want to change the logic in this commit / PR. Changing logic should not really be done in refactoring.
It makes it really hard to review / look back at things retroactively / debug regressions / etc.
Co-Authored-By: Oleg Nenashev <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code needs some fixing to pass the compilation.
Co-Authored-By: Adrien Lecharpentier <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the new version, thanks!
I plan to merge it tomorrow if no negative feedback. CC @jenkinsci/core-pr-reviewers |
Co-Authored-By: Oleg Nenashev <[email protected]>
@jsoref could you please fix the conflicts and we will propose it for merge? |
fixed, was just a tiny import issue |
let's give it another build |
This is for discussion.
Notes:
Proposed changelog entries
Internal:
Internal Java code cleanupSubmitter checklist
* Use the
Internal:
prefix if the change has no user-visible impact (API, test frameworks, etc.)Maintainer checklist
Before the changes are marked as
ready-for-merge
:Proposed changelog entries
are correctupgrade-guide-needed
label is set and there is aProposed upgrade guidelines
section in the PR title. (example)lts-candidate
Desired reviewers
@Wadeck