-
Notifications
You must be signed in to change notification settings - Fork 229
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
S2222: Branch on createdNew parameter on Mutex constructor #6994
S2222: Branch on createdNew parameter on Mutex constructor #6994
Conversation
I looked into the ITs and there are no S2222 related changes. |
@@ -23,8 +23,6 @@ public void Noncompliant(Foo foo) | |||
var m3 = Mutex.OpenExisting("x"); | |||
m3.WaitOne(); // Noncompliant | |||
|
|||
var m4 = new Mutex(); |
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.
Without this removal, the test fails. This is likely caused by the new branching and the explosion of states.
119d33f
to
ad802d1
Compare
dd4c440
to
e9c9793
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.
The TrackedSymbol change doesn't look intentional to me
analyzers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/Extensions/IOperationExtensions.cs
Show resolved
Hide resolved
...rs/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/RuleChecks/LocksReleasedAllPathsBase.cs
Outdated
Show resolved
Hide resolved
e9c9793
to
665ee9e
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.
Minor polishing
analyzers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/Extensions/IOperationExtensions.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/Extensions/IOperationExtensions.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/Extensions/IOperationExtensions.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/Extensions/IOperationExtensions.cs
Outdated
Show resolved
Hide resolved
...narAnalyzer.Common/SymbolicExecution/Roslyn/Extensions/IObjectCreationOperationExtensions.cs
Outdated
Show resolved
Hide resolved
...yzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/IObjectCreationExtensionsTest.cs
Outdated
Show resolved
Hide resolved
...yzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/IObjectCreationExtensionsTest.cs
Outdated
Show resolved
Hide resolved
...yzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/IObjectCreationExtensionsTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/IOperationExtensionsTest.cs
Show resolved
Hide resolved
...sts/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/LocksReleasedAllPaths.Mutex.cs
Show resolved
Hide resolved
d1fa962
to
d6211d9
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.
Final polish of the extension base
9c87e79
to
c5f260a
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.
LGTM
/// <summary> | ||
/// Returns the argument value corresponding to <paramref name="parameterName"/>. For <see langword="params"/> parameter an IArrayCreationOperation is returned. | ||
/// </summary> | ||
private static IOperation ArgumentValue(this ImmutableArray<IOperation> arguments, string parameterName) |
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.
Even when it's private, I wouldn't make it an extension.
private static IOperation ArgumentValue(this ImmutableArray<IOperation> arguments, string parameterName) | |
private static IOperation ArgumentValue(ImmutableArray<IOperation> arguments, string parameterName) |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Peach validation: One issue disappeared. It was related to Monitor and not to Mutex. It was flaky before so it is probably related to something else: It looks like a true negative to me. public void AddEntries(IList<IndexEntry> entries) {
Ensure.NotNull(entries, "entries");
Ensure.Positive(entries.Count, "entries.Count");
var collection = entries.Select(x => new IndexEntry(GetHash(x.Stream), x.Version, x.Position)).ToList();
// only one thread at a time can write
Interlocked.Add(ref _count, collection.Count);
var stream = collection[0].Stream; // NOTE: all entries should have the same stream
SortedList<Entry, byte> list = null;
try {
if (!_hash.TryGetValue(stream, out list)) {
list = new SortedList<Entry, byte>(MemTableComparer);
if (!Monitor.TryEnter(list, 10000)) // <-- This issue disappeared
throw new UnableToAcquireLockInReasonableTimeException();
_hash.AddOrUpdate(stream, list,
(x, y) => {
throw new Exception("This should never happen as MemTable updates are single-threaded.");
});
} else{
if (!Monitor.TryEnter(list, 10000))
throw new UnableToAcquireLockInReasonableTimeException();
}
for (int i = 0, n = collection.Count; i < n; ++i) {
var entry = collection[i];
if (entry.Stream != stream)
throw new Exception("Not all index entries in a bulk have the same stream hash.");
Ensure.Nonnegative(entry.Version, "entry.Version");
Ensure.Nonnegative(entry.Position, "entry.Position");
list.Add(new Entry(entry.Version, entry.Position), 0);
}
} finally {
if(list != null)
Monitor.Exit(list);
}
} |
Mutex has a ctor out parameter
bool createdNew
which indicates if the mutex was created and a lock is held. This parameter was ignored but we need to branch on it.Replaces #6958