Skip to content

Commit 37e37ee

Browse files
committed
C#: Add test case for cs/unsynchronized-getter with spurious result.
1 parent a232f28 commit 37e37ee

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

csharp/ql/test/query-tests/Concurrency/SynchSetUnsynchGet/SynchSetUnsynchGet.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,25 @@ int GoodProperty4
8989
lock (mutex) GoodProperty3 = value;
9090
}
9191
}
92+
93+
// GOOD: both getter and setter are locked.
94+
int? property2;
95+
int? GoodProperty5
96+
{
97+
get
98+
{
99+
lock (mutex)
100+
{
101+
property2 ??= 0;
102+
return property2;
103+
}
104+
}
105+
set
106+
{
107+
lock (mutex)
108+
{
109+
property2 = value;
110+
}
111+
}
112+
}
92113
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
| SynchSetUnsynchGet.cs:9:9:9:20 | BadProperty1 | Field $@ is guarded by a lock in the setter but not in the getter. | SynchSetUnsynchGet.cs:5:9:5:17 | property1 | property1 |
22
| SynchSetUnsynchGet.cs:23:9:23:20 | BadProperty2 | Field $@ is guarded by a lock in the setter but not in the getter. | SynchSetUnsynchGet.cs:5:9:5:17 | property1 | property1 |
3+
| SynchSetUnsynchGet.cs:95:10:95:22 | GoodProperty5 | Field $@ is guarded by a lock in the setter but not in the getter. | SynchSetUnsynchGet.cs:94:10:94:18 | property2 | property2 |

0 commit comments

Comments
 (0)