title: How do you figure out whether a CLASS is a spring proxy?
body: <p><strong>In a nutshell</strong></p>
  <p>In the <code>AopUtils</code>, we have</p>
  <pre><code>    /**
       * Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.
       * &lt;p&gt;This method additionally checks if the given object is an instance
       * of {@link SpringProxy}.
       * @param object the object to check
       * @see #isJdkDynamicProxy
       * @see #isCglibProxy
       */
      public static boolean isAopProxy(@Nullable Object object) {
          return (object instanceof SpringProxy &amp;&amp; (Proxy.isProxyClass(object.getClass()) ||
                  object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)));
      }
  </code></pre>
  <p>In now want to check whether a bean class is proxied without instantiating the bean (i.e. just with its class) in a <code>BeanFactoryPostProcessor</code>.</p>
  <p>I thought I could just &quot;translate&quot; above method:</p>
  <pre><code>    private fun &lt;T&gt; isAopProxyClass(candidate: Class&lt;T&gt;): Boolean {
          return SpringProxy::class.java.isAssignableFrom(candidate)
              &amp;&amp; (
              Proxy.isProxyClass(candidate)
                  || candidate.name.contains(CGLIB_CLASS_SEPARATOR)
              )
      }
  </code></pre>
  <p>But this does not detect proxies because <code>SpringProxy::class.java.isAssignableFrom(candidate)</code> is <code>false</code> even for obviously proxied classes.</p>
  <p>How do I make this work?</p>
  <p><strong>Full picture</strong></p>
  <p>I'm in a <code>BeanFactoryPostProcessor</code> and I need the un-proxied bean classes to access certain annotated methods by reflection.</p>
  <p>Access happens in a lambda function that will first use the <code>ApplicationContext</code> to retrieve the bean for the class. The bean must not be forcibly instantiated in this <code>BeanFactoryPostProcessor</code> (and in fact should throw an exception if it does because some beans are session-scoped).</p>
  <p><a href="https://i.stack.imgur.com/1wVuM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1wVuM.png" alt="screenshot of misbehaving code" /></a></p>