DefaultValidationResponse is not an immutable implementation
Closed this issue · 11 comments
Implementations of the interface com.jcabi.w3c.ValidationResponse
MUST be immutable and thread-safe!
The class com.jcabi.w3c.DefaultValidationResponse
implements that interface; however, it is not immutable since it has an evil setter
method.
/**
* Set validity flag.
* @param flag The flag to set
*/
public void setValid(final boolean flag) {
this.ivalid = flag;
}
This method is also unused
throughout the whole project. Why was it added?
@simonjenga looks like a bug to me, thanks
@simonjenga thanks for the report, I topped your acc for 15 mins, payment ID 72448739
@piddubnyi this ticket is yours now, please proceed, and keep in mind this. Any technical questions you should ask right here... The cost of this task is 30 mins (this is exactly how much will be paid, not less not more), when the task is done
@piddubnyi Not yet. This class is NOT thread safe as the documentation states.
If multiple threads access the mutator methods com.jcabi.w3c.DefaultValidationResponse.addError(Defect)
and com.jcabi.w3c.DefaultValidationResponse.addWarning(Defect)
, there will be ConcurrentModifications of the java.util.HashSet<Defect>
. This set must be synchronized
externally to prevent that from happening.
Also make a change on the interface class documentation to be: Implementation may be mutable BUT thread-safe.
@simonjenga Merged now with thread-safe set wrappers.
@piddubnyi An explicit lock on the mutator method is needed:
synchronized (this.hashset) {
this.hashset.add(error);
}
Also, if you take a look at: #asText(final Set<Defect> defects)
you will notice that it uses a StringBuilder
which is not thread safe.
Please take your time.
@simonjenga merged now. Let's close this, since CopyOnWriteArraySet provide enough thread safety.
@piddubnyi It looks like a contradiction. Let me close it so we can all move on.
I am closing this issue though contradictory. I wouldn't want to get in the way and withhold any Transaction ID to anyone. It would be mean to do so. A new issue related to this one may be submitted in future.
@piddubnyi 30 mins was added to your account, many thanks for your contribution (payment 74520415)! The task took 290 hours and 2 mins.
+30 to your rating, your total score is -15