[inspection] IDEA-257415 Warnings for value-based classes (Java 16)

This patch adds the inspection to detect usages of value-based classes' instances as monitors in the synchronize statement.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 178533c1415b2a8f11d48db17c19baa7e6ff4d1a
This commit is contained in:
Nikita Eshkeev
2020-12-24 04:02:33 +03:00
committed by intellij-monorepo-bot
parent 82a8d2c010
commit 7760811391
14 changed files with 243 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import valuebased.classes.AbstractValueBased;
class AC extends AbstractValueBased {
final AC ac = new AC();
final Object objectAc = new AC();
{
final AC localAc = new AC();
synchronized (<warning descr="Attempt to synchronize on an instance of a value-based class">ac</warning>) {}
synchronized (<warning descr="Attempt to synchronize on an instance of a value-based class">objectAc</warning>) {}
synchronized (<warning descr="Attempt to synchronize on an instance of a value-based class">localAc</warning>) {}
synchronized (AC.class) {}
f(ac);
g(ac);
}
void f(AC ac) {
synchronized (<warning descr="Attempt to synchronize on an instance of a value-based class">ac</warning>) {}
}
void g(Object ac) {
synchronized (ac) {}
}
}