httpcomponents:httpcore ThreadSafe class not found solution

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

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

Instead of these removed classes org.apache.http.annotation.Contract annotation and org.apache.http.annotation.ThreadingBehavior enum were introduced.

So now you should refactor @ThreadSafe occurrences to org.apache.http.annotation.Contract annotation and pass ThreadingBehavior enum‘s value SAFE to specify thread-safe behavioral contract
@Contract(threading = ThreadingBehavior.SAFE)

@NotThreadSafe transforms to ThreadingBehavior.UNSAFE

@Immutable to ThreadingBehavior.IMMUTABLE or IMMUTABLE_CONDITIONAL

Here is the full list of httpcomponents:httpcore 4.4.11 API Incompatibilities

Leave a Reply