Spring-boot: httpcore version is not compatible with httpclient version

Created on 16 Aug 2016  路  11Comments  路  Source: spring-projects/spring-boot

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>

Most helpful comment

All 11 comments

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.

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.

@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.

We're going to leave this as-is. I've added a note to the release notes.

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.

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?

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.

Sure, thanks!

Was this page helpful?
0 / 5 - 0 ratings