rspec/rules/S3551/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

71 lines
1.1 KiB
Plaintext

== Why is this an issue?
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
[source,java]
----
public class Parent {
synchronized void foo() {
//...
}
}
public class Child extends Parent {
@Override
public void foo () { // Noncompliant
// ...
super.foo();
}
}
----
=== Compliant solution
[source,java]
----
public class Parent {
synchronized void foo() {
//...
}
}
public class Child extends Parent {
@Override
synchronized void foo () {
// ...
super.foo();
}
}
----
== Resources
* 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)
=== Message
* Make this method "synchronized" to match the parent class implementation.
=== Highlighting
* method name for missing "synchronized" keyword
endif::env-github,rspecator-view[]