Skip to content

java.lang.NoSuchMethodError: ResponseEntity.getStatusCode() when running code built with Spring 5.x on Spring 6.x #29813

@derkoe

Description

@derkoe

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:

    // Test.java
    import org.springframework.http.ResponseEntity;
    
    public class Test {
      public static void main(String[] args) {
        ResponseEntity<Object> 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
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions