Skip to content

SynthesizedAnnotation is not visible from class loader [SPR-13696] #18271

Closed

Description

@spring-projects-issues

zhangchunhua opened SPR-13696 and commented

@RestController
public class UserController {

    @RequestMapping(path = "/user", method = RequestMethod.GET)
    @JsonView(User.WithoutPasswordView.class)
    public User getUser() {
        return new User("eric", "7!jd#h23");
    }
}
java.lang.IllegalArgumentException: interface org.springframework.core.annotation.SynthesizedAnnotation is not visible from class loader
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:581)
at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)
at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)
at java.lang.reflect.WeakCache.get(WeakCache.java:127)
at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)
at org.springframework.core.annotation.AnnotationUtils.synthesizeAnnotation(AnnotationUtils.java:1404)
at org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation(AnnotatedElementUtils.java:405)
at org.springframework.web.method.HandlerMethod.getMethodAnnotation(HandlerMethod.java:234)
at org.springframework.web.method.HandlerMethod$HandlerMethodParameter.getMethodAnnotation(HandlerMethod.java:290)
at org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice.supports(JsonViewResponseBodyAdvice.java:50)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyAdviceChain.processBody(RequestResponseBodyAdviceChain.java:147)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyAdviceChain.beforeBodyWrite(RequestResponseBodyAdviceChain.java:138)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:217)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:153)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:165)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:412)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)

Affects: 4.2.3

Reference URL: #18212

Issue Links:

Referenced from: commits d081470

0 votes, 7 watchers

Activity

  1. spring-projects-issues commented on Nov 18, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Are you using Swagger by any chance? If so please try to remove it to see if the error goes away. We already got several reports with that same exception and Swagger was the root cause every single time.

  2. spring-projects-issues commented on Nov 19, 2015

    @spring-projects-issues
    CollaboratorAuthor

    zhangchunhua commented

    I do not use Swagger by any chance .I just used JsonView as followed:


    @RestController
    public class UserController {
    @RequestMapping(path = "/user", method = RequestMethod.GET)
    @JsonView(User.WithoutPasswordView.class)
    public User getUser()
    { return new User("eric", "7!jd#h23"); }

    }


    In Spring4.2.2 ,this case is ok.
    But in Spring 4.2.3,when entering UserController ,IllegalArgumentException is throwed.

  3. spring-projects-issues commented on Nov 19, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Are you sure you don't have mixed versions of the framework? Can you run mvn dependencies:list on your project and check that all the Spring jars are using only 4.2.3.RELEASE? If that's the case, please share a project that reproduces the problem.

  4. spring-projects-issues commented on Nov 21, 2015

    @spring-projects-issues
    CollaboratorAuthor

    zhangchunhua commented

    Thank you very much.
    I changed my web project into maven project.
    When I used mvn dependencies, spring4.2.3.RELEASE jars and other Dependent jars automatically were downloaded.
    In this case,the IllegalArgumentException is no longer throwed.This case came to be OK.

  5. spring-projects-issues commented on Nov 24, 2015

    @spring-projects-issues
    CollaboratorAuthor

    zhangchunhua commented

    I am sorry.I am another problem.
    The same Project deployed in Tomcat,it is OK.
    But deployed in glassfish4.1,IllegalArgumentException is always throwed.
    I see that AnnotationUtils is modified form Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader() to Proxy.newProxyInstance(annotation.getClass().getClassLoader().
    Is it the reason?

    My project Link:https://github.com/syw2452/git_syw.git

  6. spring-projects-issues commented on Nov 25, 2015

    @spring-projects-issues
    CollaboratorAuthor

    zhangchunhua commented

    In glassfish4.1,this problem still exist

  7. spring-projects-issues commented on Nov 25, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    This issue is related to a wrong usage of the framework and mixed jars as we already concluded. Your sample project does not use standard Spring libraries and the fact it works in tomcat is even more suspicious. As this is a usage problem, please ask on stackoverflow and the community will hopefully assist you.

  8. spring-projects-issues commented on Dec 5, 2015

    @spring-projects-issues
    CollaboratorAuthor

    D K commented

    Not really sure why this is closed but I think there is a bug in the public api of AnnotatedElementUtils.

    Related to the allusion of cause of the exception to swagger, I believe there is a breaking change (at runtime), that was introduced in 4.2 when the implementation of HandlerMethod.getMethodAnnotation changed from

    // HandlerMethod.getMethodAnnotation implementation changed from:
        return AnnotationUtils.findAnnotation(this.method, annotationType);
    
    //to:
        return AnnotatedElementUtils.findMergedAnnotation(this.method, annotationType);

    Here is a simple test to prove it. When asking AnnotationElementUtils for an annotation that belongs the the java lang package (Deprecated) it fails with the reported exception.

    public class AClass {
      @Deprecated
      public void aMethod() {
    
      }
    }
    
    public class ATest {
      @Test
      public void testAnnotation() throws NoSuchMethodException {
        AnnotatedElement method = AClass.class.getMethod("aMethod");
        AnnotatedElementUtils.findMergedAnnotation(method, Deprecated.class);
      }
    }

    Would you like me to create a new bug for this?

  9. spring-projects-issues commented on Dec 5, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Let's reopen this one and repurpose it a bit: The hint with lookup of a JDK annotation is key here, since it'll be hard to synthesize those to begin with. In particular, we need to pay attention which class loader we're using for the synthesized type.

    Juergen

  10. spring-projects-issues commented on Dec 7, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    We are explicitly checking whether the SynthesizedAnnotation marker is exposable to the annotation's own ClassLoader now. If not, we simply expose a plain annotation proxy without that marker type.

    In order to nevertheless detect pre-synthesized annotations, we also check for the annotation proxy's InvocationHandler: If it's our internal one, we consider the annotation as pre-synthesized as well.

    Juergen

  11. spring-projects-issues commented on Dec 8, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Thibault Kruse commented

    Same problem, using swagger via com.mangofactory:swagger-springmvc and switched from 4.2.2 to 4.2.3. Not mixing Spring library version (though using Spring security 4.0.3).
    Also see: springfox/springfox#1055

  12. spring-projects-issues commented on Dec 8, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Please give the latest 4.2.4.BUILD-SNAPSHOT a try and let me know whether it works for you there...

    Juergen

  13. spring-projects-issues commented on Dec 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Thibault Kruse commented

    That's rather painful, as of now, 4.2.4.RELEASE-BUILD does not exist for e.g. spring-test or spring-context, spring-aop...

  14. spring-projects-issues commented on Dec 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    What RELEASE-BUILD? As Juergen point out, the proper version is 4.2.4.BUILD-SNAPSHOT.

  15. spring-projects-issues commented on Dec 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Thibault Kruse commented

    Sorry, that's what I meant. 4.2.4.BUILD-SNAPSHOT is not defined for spring-test, spring-context, spring-aop.
    See here:
    https://repo.spring.io/snapshot/org/springframework/spring-context/4.2.4.BUILD-SNAPSHOT/

    All poms are timestamped, and my maven thus does not seem to find 4.2.4.BUILD-SNAPSHOT. Maybe I did something else wrong...

  16. spring-projects-issues commented on Dec 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    snapshot builds are always timestamped. I don't know what you're doing but it works for me. Maybe you need to add the spring snapshots repo in your pom?

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
  17. spring-projects-issues commented on Dec 11, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Thibault Kruse commented

    ok, sorry for the confusion. 4.2.4.BUILD-SNAPSHOT seems to work for me.

  18. added
    type: bug
    in: core
    on Jan 11, 2019
  19. added this to the 4.2.4 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions