Skip to content

NoSuchMethodError when running with Spring Boot 4.x (Spring Framework 7.x) due to HttpHeaders.remove signature change #1162

@zhaoyuhuang-oss

Description

@zhaoyuhuang-oss

Describe the Problem

We are currently integrating your library into an application based on Spring Boot 4.x (which depends on Spring Framework 7.x). Upon application startup, we encounter a NoSuchMethodError. Here is the error log generated during startup:

Stack Trace

Description: An attempt was made to call a method that does not exist. The attempt was made from the following location:

com.sap.cloud.sdk.services.openapi.apiclient.ApiClient.addDefaultHeader(ApiClient.java:341)

The following method did not exist:

'java.util.List org.springframework.http.HttpHeaders.remove(java.lang.Object)'

The calling method's class, com.sap.cloud.sdk.services.openapi.apiclient.ApiClient, was loaded from the following location:
jar:file:/home/vcap/app/BOOT-INF/lib/openapi-core-5.28.0.jar!/com/sap/cloud/sdk/services/openapi/apiclient/ApiClient.class

The called method's class, org.springframework.http.HttpHeaders, is available from the following locations:
jar:file:/home/vcap/app/BOOT-INF/lib/spring-web-7.0.6.jar!/org/springframework/http/HttpHeaders.class

Root Cause Analysis

The root cause appears to be a compatibility issue with Spring Framework 7.x. Your library currently depends on Spring 6.2.18.
In Spring Framework 7.x, the signature of the remove method in org.springframework.http.HttpHeaders has changed, and the method accepting a generic Object key no longer exists.

  • Method removed in Spring 7.x:

@Override public List<String> remove(Object key) { return this.headers.remove(key); }

  • New method signature in Spring 7.x:
    public @Nullable List<String> remove(String key) { return this.headers.remove(key); }

Propose a Solution

To resolve this compatibility issue, could you please upgrade the Spring Framework dependency in your library to a version compatible with Spring 7.x (or higher)? This will ensure that the ApiClient class aligns with the updated HttpHeaders API.

Describe Alternatives

No response

Affected Development Phase

Release

Impact

Blocked

Timeline

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions