class Outer {
int field;
synchronized void outer() {
if (field > 2) field *= -1;
}
class Inner {
synchronized void inner() {
field++;
}
}
}
However, when not stripped down to this test case, it can be hard to notice. IDEA should highlight the field, or highlight each synchronized keyword, or each field access, to notify the developer of the bug. Hopefully the inspection could track synchronization on (final) fields as well as on "this" for any inner class, so this case would be caught:
class Outer {
int field;
synchronized void outer() {
if (field > 2) field *= -1;
}
class Inner {
synchronized void inner() {
field++;
}
}
}
However, when not stripped down to this test case, it can be hard to notice. IDEA should highlight the field, or highlight each synchronized keyword, or each field access, to notify the developer of the bug. Hopefully the inspection could track synchronization on (final) fields as well as on "this" for any inner class, so this case would be caught: