rspec/rules/S1844/java/rule.adoc

43 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
From the Java API documentation:
____
``++Condition++`` factors out the ``++Object++`` monitor methods (``++wait++``, ``++notify++`` and ``++notifyAll++``) into distinct objects to give the effect of having multiple wait-sets per object, by combining them with the use of arbitrary Lock implementations. Where a ``++Lock++`` replaces the use of ``++synchronized++`` methods and statements, a ``++Condition++`` replaces the use of the ``++Object++`` monitor methods.
____
The purpose of implementing the ``++Condition++`` interface is to gain access to its more nuanced ``++await++`` methods. Therefore, calling the method ``++Object.wait(...)++`` on a class implementing the ``++Condition++`` interface is silly and confusing.
=== 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
----
final Lock lock = new ReentrantLock();
final Condition notFull = lock.newCondition();
...
notFull.wait();
----
=== 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
----
final Lock lock = new ReentrantLock();
final Condition notFull = lock.newCondition();
...
notFull.await();
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]