Skip to content

MvcUriComponentsBuilder.fromMethodCall breaks for controller with CharSequence return type #30210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hinnerkoetting opened this issue Mar 28, 2023 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@hinnerkoetting
Copy link

I am currently trying to upgrade to upgrade to Spring 5.3.26 (from 5.3.26, via Spring Boot 2.7.10) and encounter an error when using MvcUriComponentsBuilder.fromMethodCall for a controller that returns CharSequence. I believe this error is caused by this change: #29913

Stacktrace

Caused by: java.lang.IllegalStateException: Failed to create proxy for controller method return type: public java.lang.CharSequence com.example.OurController.show(javax.servlet.http.HttpServletRequest,org.springframework.ui.Model,java.lang.String,java.lang.String,java.lang.Boolean,org.springframework.security.core.userdetails.UserDetails)
	at org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder$ControllerMethodInvocationInterceptor.intercept(MvcUriComponentsBuilder.java:737)
	at com.example.OurController$$EnhancerBySpringCGLIB$$b5e40016.show(<generated>)
Caused by: java.lang.IllegalArgumentException: org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder$MethodInvocationInfo referenced from a method is not visible from class loader
	at java.base/java.lang.reflect.Proxy$ProxyBuilder.ensureVisible(Proxy.java:883)
	at java.base/java.lang.reflect.Proxy$ProxyBuilder.validateProxyInterfaces(Proxy.java:721)
	at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:648)
	at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$1(Proxy.java:440)
	at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329)
	at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205)
	at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:438)
	at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037)

Our code

@Controller
public class OurController {
  public CharSequence show(...) {
     return "some-view";
  }
}
...
public class OurService {
  public String getUrl() {
    return MvcUriComponentsBuilder
                .fromMethodCall(on(OurController.class).show(...)
                .build()
                .encode();
  }
}

After change #29913 MvcUriComponentsBuilder uses the classloader of the return type (in our case CharSequence) which returns null which causes the issue above.

Workaround

It's possible to return ModelAndView instead of CharSequence to fix this issue.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 28, 2023
@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 28, 2023
@jhoeller jhoeller self-assigned this Mar 28, 2023
@jhoeller jhoeller added this to the 6.0.8 milestone Mar 28, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x labels Mar 28, 2023
@jhoeller jhoeller changed the title MvcUriComponentsBuilder.fromMethodCall breaks since 5.3.26 MvcUriComponentsBuilder.fromMethodCall breaks for controller with CharSequence return type Mar 28, 2023
jhoeller added a commit that referenced this issue Mar 28, 2023
jhoeller added a commit that referenced this issue Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants