This snippet of code worked fine in 2.7 but not caching in 3.2.2

    @Cacheable(condition = "#objectId != null")
    public String getObject(String objectId) {
        if (objectId == null) {
            return null;
        }
        System.out.println("Fetching object for objectId " + objectId);
        return "some value";
    }

However, if I remove the condition, the cache seems to work.

Expected output from junit

Fetching object for objectId xyz
Fetching object for objectId abc

However, seeing

Fetching object for objectId xyz
Fetching object for objectId xyz
Fetching object for objectId abc
Fetching object for objectId abc

Attaching a sample project ehcache.zip

Comment From: scottfrederick

This is a duplicate of https://github.com/spring-projects/spring-framework/issues/32117. Starting with Spring Framework 6,1, your code must be compiled with -parameters for the condition to take effect (Spring Boot has nothing to do with this issue except that Spring Boot 3.2 depends on Spring Framework 6.1).

If you inherit the Spring Boot partent POM, then -parameters will be added to the compile configuration automatically. If you don't inherit from Spring Boot then you can manually configure the compiler with something like this in your pom.xml:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <parameters>true</parameters>
                </configuration>
            </plugin>