Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8335333

Jdk DynamicProxy throw java.lang.NoClassDefFoundError

XMLWordPrintable

    • b01
    • 17
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      run my code, I excepted StackOverflowError,but it print error : java.lang.NoClassDefFoundError: Could not initialize class java.lang.reflect.UndeclaredThrowableException why? this is bug?

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected StackOverflowError
      ACTUAL -
      java.lang.NoClassDefFoundError: Could not initialize class java.lang.reflect.UndeclaredThrowableException

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Proxy;
      import java.lang.reflect.UndeclaredThrowableException;


      public class JdkDynamicProxy {
          public static void main(String[] args) {
      // new UndeclaredThrowableException(new RuntimeException());
              ClassLoader classLoader = JdkDynamicProxy.class.getClassLoader();
              MaiPiao proxyMaiPiao = (MaiPiao) Proxy.newProxyInstance(classLoader, new Class[]{MaiPiao.class}, (proxy, method, args1) -> {
                  if(method.getName().equals("maiPiao")){
                      System.out.println("卖票");
                      return null;
                  }else if(method.getName().equals("getName")){
                      return "name1";
                  }
                  return method.invoke(proxy);
              });
              proxyMaiPiao.maiPiao();
              String name = proxyMaiPiao.getName();
              System.out.println(name);
              proxyMaiPiao.doSomething();
          }

          public interface MaiPiao{
              void maiPiao();

              String getName();

              void doSomething();
          }
      }

      ---------- END SOURCE ----------

            liach Chen Liang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: