[Java] Replacement of annotation ThreadSafe/NotThreadSafe removed in httpcore-4.4.5

less than 1 minute read

annotations available in httpcore-4.4.4 but removed from httpcore-4.4.5

Replacement notes for @ThreadSafe, @NotThreadSafe.

Release Note: https://archive.apache.org/dist/httpcomponents/httpcore/RELEASE_NOTES-4.4.x.txt

httpcore ThreadSafe class not found solution: https://dev-aux.com/java/org-apache-http-annotation-threadsafe-class-not-found

Replace

@ThreadSafe class not found compilation error occurs after updating your org.apache.httpcomponents:httpcore dependency version to 4.4.11 or above. @NotThreadSafe

org.apache.http.annotation.Immutable
org.apache.http.annotation.NotThreadSafe
org.apache.http.annotation.ThreadSafe

Instead of these being removed, the org.apache.http.annotation.Contract and org.apache.http.annotation.ThreadingBehavior enums were introduced.

Therefore, by replacing @ThreadSafe with org.apache.http.annotation.Contract and passing the ThreadingBehavior enum value SAFE, you can specify the thread-safe operation contract.

Example

@Contract(threading = org.apache.http.annotation.ThreadingBehavior.SAFE)

And so on.

Similarly @NotThreadSafe is @Contract(threading = org.apache.http.annotation.ThreadingBehavior.UNSAFE)

@Immutable is ThreadingBehavior.IMMUTABLE or IMMUTABLE_CONDITIONAL

See also: https://hc.apache.org/httpcomponents-core-ga/httpcore/clirr-report.html