Skip to content

fix(webflux): fix NoSuchMethodError when using spring framework 7 with webflux#4515

Open
jihad-bouhaiji wants to merge 5 commits into
elastic:mainfrom
jihad-bouhaiji:fix/webflux-spring-7-support
Open

fix(webflux): fix NoSuchMethodError when using spring framework 7 with webflux#4515
jihad-bouhaiji wants to merge 5 commits into
elastic:mainfrom
jihad-bouhaiji:fix/webflux-spring-7-support

Conversation

@jihad-bouhaiji

Copy link
Copy Markdown

What does this PR do?

This PR fixes an issue with the experimental support for Spring framework 7 that was added PR. When running the agent, it will throw a NoSuchMethodError exception due to the HttpHeaders.entrySet method. This is due to HttpHeaders no longer implementing the MultiValueMap contract.
I have changed the copying of header to only use API's that are still available across version 5, 6 and 7.
The test co.elastic.apm.agent.springwebflux.AbstractServerInstrumentationTest#dispatchHello covers this fix.

Checklist

  • This is an enhancement of existing features, or a new feature in existing plugins
    • I have updated CHANGELOG.next-release.md
    • I have added tests that prove my fix is effective or that my feature works
    • Added an API method or config option? Document in which version this will be introduced
    • I have made corresponding changes to the documentation
  • This is a bugfix
  • This is a new plugin
    • I have updated CHANGELOG.next-release.md
    • My code follows the style guidelines of this project
    • I have made corresponding changes to the documentation
    • I have added tests that prove my fix is effective or that my feature works
    • New and existing unit tests pass locally with my changes
    • I have updated supported-technologies.md
    • Added an API method or config option? Document in which version this will be introduced
    • Added an instrumentation plugin? Describe how you made sure that old, non-supported versions are not instrumented by accident.
  • This is something else

@jihad-bouhaiji jihad-bouhaiji requested a review from a team as a code owner June 17, 2026 08:21
@github-actions

Copy link
Copy Markdown

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@github-actions github-actions Bot added agent-java community Issues and PRs created by the community triage labels Jun 17, 2026

@SylvainJuge SylvainJuge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to add an explicit test that allows to reproduce it ? Is the issue happening with the version that is being used for compilation ? if yes, then a simple unit test should be enough. If not, then do you have a sample application that allows to reproduce the issue ?

Comment on lines +319 to +320
// This is the only way I could find to make a multiValueMap without having access
// to the api from spring framework 7 that will work across versions 5, 6 and 7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] reword the comment to explain the "why".

Suggested change
// This is the only way I could find to make a multiValueMap without having access
// to the api from spring framework 7 that will work across versions 5, 6 and 7
// This allows to to make a MultiValueMap without having access
// to the api from spring framework 7 that will work across versions 5, 6 and 7

// This is the only way I could find to make a multiValueMap without having access
// to the api from spring framework 7 that will work across versions 5, 6 and 7
Map<String, List<String>> multiValueHeaderMap = source.toSingleValueMap().keySet()
.parallelStream().collect(Collectors.toMap(Function.identity(), new Function<>() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] we don't need a parallelStream here as only a few values are expected, so it is probably better to use the non parallel one.

@jihad-bouhaiji

Copy link
Copy Markdown
Author

I added a module apm-spring-webflux-plugin-spring7 and apm-spring-webflux-testapp-spring7 that tests the same flows that we have for Spring 6 in apm-spring-webflux-plugin. That will catch any breaking api mismatch across 5, 6, and 7.\

I do have a question.
It turns out that the api for HttpHeaders.get() has also changed in springframework 7. So I changed it to use getValuesAsList. However for the test co.elastic.apm.agent.springwebflux.AbstractServerInstrumentationTest#hello, it expects a comma seperated string for the header "Accept" instead of a List of Strings.
I have changed the test to reflect that the headers are copied as a list instead of one String, but i want to double check with you if that was okay, or if i should parse all multi value headers into one comma seperated string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-java community Issues and PRs created by the community triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants