rspec/rules/S3551/java/rule.adoc

65 lines
1.0 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
When ``++@Overrides++`` of ``++synchronized++`` methods are not themselves ``++synchronized++``, the result can be improper synchronization as callers rely on the thread-safety promised by the parent class.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class Parent {
synchronized void foo() {
//...
}
}
public class Child extends Parent {
@Override
public void foo () { // Noncompliant
// ...
super.foo();
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class Parent {
synchronized void foo() {
//...
}
}
public class Child extends Parent {
@Override
synchronized void foo () {
// ...
super.foo();
}
}
----
== Resources
2021-04-28 16:49:39 +02:00
* https://wiki.sei.cmu.edu/confluence/x/gzdGBQ[CERT, TSM00-J] - Do not override thread-safe methods with methods that are not thread-safe
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]