Affects: 6.0.x - tested with 6.0.4


The signature of ResponseEntity#getStatusCode was changed in Spring Framework 6.x - it now returns HttpStatusCode (Spring 5.x returned HttpStatus) - see #28214. The idea was that the change is backward compatible.

How to reproduce:

  1. Create this simple test class in a file Test.java: ```java // Test.java import org.springframework.http.ResponseEntity;

    public class Test { public static void main(String[] args) { ResponseEntity ok = ResponseEntity.ok().build(); if (ok.getStatusCode().is2xxSuccessful()) { System.out.println("OK"); } } } 2. Compile the application with Spring 5.3.x: javac -cp $HOME/.m2/repository/org/springframework/spring-web/5.3.24/spring-web-5.3.24.jar Test.java 3. Run the application with Spring 6.0x: java -cp "$HOME/.m2/repository/org/springframework/spring-web/6.0.4/spring-web-6.0.4.jar:$HOME/.m2/repository/org/springframework/spring-core/6.0.4/spring-core-6.0.4.jar:." Test Exception in thread "main" java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.ResponseEntity.getStatusCode()' at Test.main(Test.java:6) ```

    With Spring 5.3.x it works as expected: java -cp "$HOME/.m2/repository/org/springframework/spring-web/5.3.24/spring-web-5.3.24.jar:$HOME/.m2/repository/org/springframework/spring-core/5.3.24/spring-core-5.3.24.jar:." Test OK

    Comment From: bclozel

    This change was done in a source compatible way, but not binary compatible way. We don't guarantee binary compatibility between major versions, you should recompile the application with Spring Framework 6.0 on the classpath.

    Comment From: derkoe

    @bclozel the issue is here that you cannot create a library that is Spring 5.x and 6.x compatible. Is this really intended?

    Comment From: derkoe

    This incompatibility also exists in the other direction - code compile with 6.0.x is not running with 5.3.x

    $ javac -cp $HOME/.m2/repository/org/springframework/spring-web/6.0.4/spring-web-6.0.4.jar Test.java
    $ java -cp "$HOME/.m2/repository/org/springframework/spring-web/5.3.24/spring-web-5.3.24.jar:$HOME/.m2/repository/org/springframework/spring-core/5.3.24/spring-core-5.3.24.jar:." Test
    Exception in thread "main" java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatusCode org.springframework.http.ResponseEntity.getStatusCode()'
            at Test.main(Test.java:6)
    

    Comment From: bclozel

    @derkoe we do our best to retain compatibility, but keeping binary compatibility between major versions is a huge ask. I'm sorry for the inconvenience, but in this case we think the tradeoff is worth it.

    You cannot create a library that is Spring 5.x and 6.x compatible in the first place anyway: they have different Java baselines. If you're compiling your library with Java 17, it's not compatible with all Spring 5.x applications.

    .