Hi,
httpcore.version was updated from 4.4.4 to 4.4.5 with: https://github.com/spring-projects/spring-boot/issues/6165 https://github.com/spring-projects/spring-boot/commit/ed2586d38d168ff1c760461505b1a876b678c2b8
This is causing the following compilation error on my setup:
[ERROR] diagnostic: error: cannot access org.apache.http.annotation.Immutable
class file for org.apache.http.annotation.Immutable not found
After some digging, I've found that httpclient:4.5.2 is not compatible with httpcore:4.4.5 because class org.apache.http.annotation.Immutable was removed from httpcore:4.4.5 and httpclient:4.5.2 still uses it: https://hc.apache.org/httpcomponents-core-4.4.x/httpcore/clirr-report.html https://svn.apache.org/repos/asf/httpcomponents/httpclient/tags/4.5.2/httpclient/src/main/java/org/apache/http/impl/client/HttpClients.java
As a workaround I had to override this by adding the following to my pom properties:
<httpcore.version>4.4.4</httpcore.version>
Comment From: wilkinsona
Can you share some code that reproduces the compilation error? I'm surprised that the annotation isn't ignored if it's not on the class path.
Comment From: matosf
Here you go, a minimum project with my specific case: https://github.com/matosf/spring-boot-issue-6662
Seems to happen if you have annotation processing going on (like with the org.immutables:value lib) and you create a class that extends one that has the removed @Immutable annotation.
Comment From: wilkinsona
@matosf Thank you. I've learned something about annotation processing behaviour today. FWIW, Boot's own annotation processor is also affected so it appears to be a general annotation processing problem.
Looking at httpcore, it looks like it's a deliberate backwards-incompatible change. The annotation was removed in https://github.com/apache/httpcore/commit/9e065bad07c9ca771c42e5b4f1dc12118c5e75c9 and the package excluded from binary compatibility checks in https://github.com/apache/httpcore/commit/0271b0b4123da453121eb9c1dfe638c92ab64e39.
I'm not sure what our best course of action is here. The problem feels like an edge case. In addition to the workaround of downgrading to 4.4.4, you also have the option of structuring your code such that a class that extends an Http Client class with one of the removed annotations isn't seen by any annotation processors. I'm tempted to leave things the way they are along with a note in the release notes / documentation. Let's see what the rest of the team thinks.
Comment From: wilkinsona
We're going to leave this as-is. I've added a note to the release notes.
Comment From: snicoll
And here's the backstory about the missing annotation.
Comment From: yacota
We are updating from boot 1.2.8 to 1.3.8 (not to 1.4.x because we do not yet want to update to the latest spring-data release) and we faced this issue too. Maybe adding https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#annotation-processing to 1.3 release notes could help others.
Comment From: wilkinsona
@yacota Done: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes#annotation-processing. Thanks for the suggestion.
Comment From: SirR4T
Hi @wilkinsona , regarding
you also have the option of structuring your code such that a class that extends an Http Client class with one of the removed annotations isn't seen by any annotation processors.
, could you explain this a bit further? Seems like I'm running into this same issue, although with the @NotThreadSafe annotation (when trying to extend the HttpEntityEnclosingRequestBase class).
I do not yet fully understand how the annotation processors work, so what kind of code restructuring would help hide the problematic class?
Comment From: wilkinsona
what kind of code restructuring would help hide the problematic class?
Move the code into a module where it won't be processed by an annotation processor.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Comment From: SirR4T
Sure, thanks!
Comment From: ItaiFonio
Found this article - hope that helps http://dev-aux.com/java/org-apache-http-annotation-threadsafe-class-not-found
Comment From: waseem-ishaq
Im using httpclient-4.5.2 dependency in this method " HttpComponentsClientHttpRequestFactory(HttpClient()); " it required HttpClient from "httpclient5" how can i resolve this issues
Comment From: wilkinsona
All supported versions of Spring Boot (3.1.x and later), require HttpClient 5. You should update to HttpClient 5 in order to use a supported version of Spring Boot. Alternatively, you could downgrade to an unsupported version of Spring Boot but this is not recommended.
If you have any further questions, please follow up on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.