NoClassDefFoundError when I call RestTemplate.exchange() on a fake api

13 views
Skip to first unread message

David Guiney

unread,
Oct 2, 2019, 5:59:40 PM10/2/19
to jackson-user

I upgraded jackson-databind lib to 2.10.0.pr3 to overcome some Veracode vulnerabilities and now one of my tests is failing on calling RestTemplate.exchange() on a bad api.

The RequestEntity has a url of http://localhost:9999/fake/api and HttpMethod = POST. I have a custom dto for a response type.


getRestTemplate().exchange(requestEntity, MyResponseDto.class);


My test initially expected a ResourceAccessException, and this worked ok up to 2.9.10.


After upgrade, when I debug into the library code into org.springframework.web.client.RestTemplate.doExecute() the call on line 733, requestCallback.doWithRequest(request) throws a NoClassDefFoundError and I cannot find any implementation of that method.


Is there some new setup required? Do I need to implement the RequestCallback in my code and write a concrete implementation of doExecute? I tried this with a simple logging, but it did not break there, and I think that would be a regression of the library if I needed to do this.

Tatu Saloranta

unread,
Oct 2, 2019, 7:03:33 PM10/2/19
to jackson-user
None of this code is in Jackson yet, so you'd have to find name of
class that was not found.

But typically problems like this are due version incompatibility, and
most commonly it is an older version of a dependency.

For example: `jackson-databind` version 2.9.10 would expect methods
from 2.9.x of `jackson-core` (streaming API), so having `jackson-core`
2.7.9 in classpath would very likely produce a `ClassDefNotFoundError`
when class it was compiled against was missing from runtime
environment.
Reverse is not the case, so having newer version of `jackson-core`
would usually not be a problem wrt `jackson-databind`. But the easiest
way to avoid problems is to enforce same minor version (and while
doing that, just sync up to same patch) for all Jackson components.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages