test_class.file: dubbo-rpc/dubbo-rpc-api/src/test/java/com/alibaba/dubbo/rpc/filter/ExceptionFilterTest.java
test_class.identifier: ExceptionFilterTest
test_case.body: @SuppressWarnings("unchecked")
      @Test
      public void testRpcException() {
          Logger logger = mock(Logger.class);
          RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
          RpcException exception = new RpcException("TestRpcException");
  
          ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
          RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
          Invoker<DemoService> invoker = mock(Invoker.class);
          given(invoker.getInterface()).willReturn(DemoService.class);
          given(invoker.invoke(eq(invocation))).willThrow(exception);
  
  
          try {
              exceptionFilter.invoke(invoker, invocation);
          } catch (RpcException e) {
              assertEquals("TestRpcException", e.getMessage());
          }
          Mockito.verify(logger).error(eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: "
                  + DemoService.class.getName() + ", method: sayHello, exception: "
                  + RpcException.class.getName() + ": TestRpcException"), eq(exception));
          RpcContext.removeContext();
      }
test_case.class_method_signature: ExceptionFilterTest.testRpcException()
test_case.full_signature: @SuppressWarnings("unchecked") @Test public void testRpcException()
test_case.identifier: testRpcException
test_case.invocations: mock setRemoteAddress getContext mock willReturn given getInterface willThrow given invoke eq invoke assertEquals getMessage error verify eq getName getName eq removeContext
test_case.modifiers: @SuppressWarnings("unchecked") @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRpcException()
focal_class.declarator: logger
focal_class.modifier: private final
focal_class.original_string: private final Logger logger;
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ExceptionFilter.java
focal_class.identifier: ExceptionFilter
focal_class.interfaces: implements Filter
focal_class.class_method_signature: ExceptionFilter.ExceptionFilter()
focal_class.full_signature: public  ExceptionFilter()
focal_class.identifier: ExceptionFilter
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  ExceptionFilter()
focal_class.class_method_signature: ExceptionFilter.ExceptionFilter(Logger logger)
focal_class.full_signature: public  ExceptionFilter(Logger logger)
focal_class.identifier: ExceptionFilter
focal_class.modifiers: public
focal_class.parameters: (Logger logger)
focal_class.signature:  ExceptionFilter(Logger logger)
focal_class.class_method_signature: ExceptionFilter.invoke(Invoker<?> invoker, Invocation invocation)
focal_class.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation invocation)
focal_class.identifier: invoke
focal_class.modifiers: @Override public
focal_class.parameters: (Invoker<?> invoker, Invocation invocation)
focal_class.return: Result
focal_class.signature: Result invoke(Invoker<?> invoker, Invocation invocation)
focal_method.body: @Override
      public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
          try {
              Result result = invoker.invoke(invocation);
              if (result.hasException() && GenericService.class != invoker.getInterface()) {
                  try {
                      Throwable exception = result.getException();
  
                      // directly throw if it's checked exception
                      if (!(exception instanceof RuntimeException) && (exception instanceof Exception)) {
                          return result;
                      }
                      // directly throw if the exception appears in the signature
                      try {
                          Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                          Class<?>[] exceptionClassses = method.getExceptionTypes();
                          for (Class<?> exceptionClass : exceptionClassses) {
                              if (exception.getClass().equals(exceptionClass)) {
                                  return result;
                              }
                          }
                      } catch (NoSuchMethodException e) {
                          return result;
                      }
  
                      // for the exception not found in method's signature, print ERROR message in server's log.
                      logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost()
                              + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName()
                              + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception);
  
                      // directly throw if exception class and interface class are in the same jar file.
                      String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface());
                      String exceptionFile = ReflectUtils.getCodeBase(exception.getClass());
                      if (serviceFile == null || exceptionFile == null || serviceFile.equals(exceptionFile)) {
                          return result;
                      }
                      // directly throw if it's JDK exception
                      String className = exception.getClass().getName();
                      if (className.startsWith("java.") || className.startsWith("javax.")) {
                          return result;
                      }
                      // directly throw if it's dubbo exception
                      if (exception instanceof RpcException) {
                          return result;
                      }
  
                      // otherwise, wrap with RuntimeException and throw back to the client
                      return new RpcResult(new RuntimeException(StringUtils.toString(exception)));
                  } catch (Throwable e) {
                      logger.warn("Fail to ExceptionFilter when called by " + RpcContext.getContext().getRemoteHost()
                              + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName()
                              + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
                      return result;
                  }
              }
              return result;
          } catch (RuntimeException e) {
              logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost()
                      + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName()
                      + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
              throw e;
          }
      }
focal_method.class_method_signature: ExceptionFilter.invoke(Invoker<?> invoker, Invocation invocation)
focal_method.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation invocation)
focal_method.identifier: invoke
focal_method.invocations: invoke hasException getInterface getException getMethod getInterface getMethodName getParameterTypes getExceptionTypes equals getClass error getRemoteHost getContext getName getInterface getMethodName getName getClass getMessage getCodeBase getInterface getCodeBase getClass equals getName getClass startsWith startsWith toString warn getRemoteHost getContext getName getInterface getMethodName getName getClass getMessage error getRemoteHost getContext getName getInterface getMethodName getName getClass getMessage
focal_method.modifiers: @Override public
focal_method.parameters: (Invoker<?> invoker, Invocation invocation)
focal_method.return: Result
focal_method.signature: Result invoke(Invoker<?> invoker, Invocation invocation)