Hello lovely Mockkers! In my test, this line wher...
# mockk
n
Hello lovely Mockkers! In my test, this line where I mock a return from
repository
Copy code
every { repository.save(any()) } returns fleetEntity
Returns the following after switching JDK from Eclipse Temurin to docker.io/ibm-semeru-runtimes:open-17.0.13_11-jdk
Copy code
FleetServiceTest > should return created fleet given request() FAILED
    io.mockk.MockKException at FleetServiceTest.kt:44
        Caused by: java.lang.ClassCastException at FleetServiceTest.kt:44
repository interface:
Copy code
package org.springframework.data.repository;

import java.util.Optional;

@NoRepositoryBean
public interface CrudRepository<T, ID> extends Repository<T, ID> {
    <S extends T> S save(S entity);

    <S extends T> Iterable<S> saveAll(Iterable<S> entities);

    Optional<T> findById(ID id);

    boolean existsById(ID id);

    Iterable<T> findAll();

    Iterable<T> findAllById(Iterable<ID> ids);

    long count();

    void deleteById(ID id);

    void delete(T entity);

    void deleteAllById(Iterable<? extends ID> ids);

    void deleteAll(Iterable<? extends T> entities);

    void deleteAll();
}
Any ideas as to why this CastException occurs all of a sudden after changing the JDK? This is important because the new JDK image has a significantly smaller memory footprint.
d
The problem is probably outside of the code you've shared. My first instinct would be to make sure the class-path is clean. Doing a full rebuild might help. I'd also consider setting a breakpoint where that exception occurs and seeing what the actual type is before the cast. That may provide a clue.
e
as I mentioned in the other thread, mockk may have some issues when running on IBM OpenJ9 that aren't on Oracle Hotspot: https://github.com/mockk/mockk/issues/726
🙌 1
n
I am trying to reproduce the error, so I changed my local JDK in IntelliJ but the test passes....???
d
Yeah, sounds like an issue with the JDK itself.