test_class.declarator: genericFilter = new GenericFilter()
test_class.original_string: GenericFilter genericFilter = new GenericFilter();
test_class.type: GenericFilter
test_class.var_name: genericFilter
test_class.file: dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java
test_class.identifier: GenericFilterTest
test_case.body: @Test
      public void testInvokeWithMethodArgumentSizeIsNot3() {
  
          Method genericInvoke = GenericService.class.getMethods()[0];
  
          Map<String, Object> person = new HashMap<String, Object>();
          person.put("name", "dubbo");
          person.put("age", 10);
  
          RpcInvocation invocation = new RpcInvocation($INVOKE, GenericService.class.getName(), "", genericInvoke.getParameterTypes()
                  , new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}});
  
          URL url = URL.valueOf("test://test:11/org.apache.dubbo.rpc.support.DemoService?" +
                  "accesslog=true&group=dubbo&version=1.1");
          Invoker invoker = Mockito.mock(Invoker.class);
          when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse(new Person("person", 10)));
          when(invoker.getUrl()).thenReturn(url);
          when(invoker.getInterface()).thenReturn(DemoService.class);
  
          Result result = genericFilter.invoke(invoker, invocation);
          Assertions.assertEquals(Person.class, result.getValue().getClass());
          Assertions.assertEquals(10, ((Person) (result.getValue())).getAge());
      }
test_case.class_method_signature: GenericFilterTest.testInvokeWithMethodArgumentSizeIsNot3()
test_case.full_signature: @Test public void testInvokeWithMethodArgumentSizeIsNot3()
test_case.identifier: testInvokeWithMethodArgumentSizeIsNot3
test_case.invocations: getMethods put put getName getParameterTypes getCanonicalName valueOf mock thenReturn when invoke any thenReturn when getUrl thenReturn when getInterface invoke assertEquals getClass getValue assertEquals getAge getValue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInvokeWithMethodArgumentSizeIsNot3()
focal_class.file: dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java
focal_class.identifier: GenericFilter
focal_class.interfaces: implements Filter, Filter.Listener
focal_class.class_method_signature: GenericFilter.invoke(Invoker<?> invoker, Invocation inv)
focal_class.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation inv)
focal_class.identifier: invoke
focal_class.modifiers: @Override public
focal_class.parameters: (Invoker<?> invoker, Invocation inv)
focal_class.return: Result
focal_class.signature: Result invoke(Invoker<?> invoker, Invocation inv)
focal_class.class_method_signature: GenericFilter.onResponse(Result appResponse, Invoker<?> invoker, Invocation inv)
focal_class.full_signature: @Override public void onResponse(Result appResponse, Invoker<?> invoker, Invocation inv)
focal_class.identifier: onResponse
focal_class.modifiers: @Override public
focal_class.parameters: (Result appResponse, Invoker<?> invoker, Invocation inv)
focal_class.return: void
focal_class.signature: void onResponse(Result appResponse, Invoker<?> invoker, Invocation inv)
focal_class.class_method_signature: GenericFilter.onError(Throwable t, Invoker<?> invoker, Invocation invocation)
focal_class.full_signature: @Override public void onError(Throwable t, Invoker<?> invoker, Invocation invocation)
focal_class.identifier: onError
focal_class.modifiers: @Override public
focal_class.parameters: (Throwable t, Invoker<?> invoker, Invocation invocation)
focal_class.return: void
focal_class.signature: void onError(Throwable t, Invoker<?> invoker, Invocation invocation)
focal_method.body: @Override
      public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
          if ((inv.getMethodName().equals($INVOKE) || inv.getMethodName().equals($INVOKE_ASYNC))
                  && inv.getArguments() != null
                  && inv.getArguments().length == 3
                  && !GenericService.class.isAssignableFrom(invoker.getInterface())) {
              String name = ((String) inv.getArguments()[0]).trim();
              String[] types = (String[]) inv.getArguments()[1];
              Object[] args = (Object[]) inv.getArguments()[2];
              try {
                  Method method = ReflectUtils.findMethodByMethodSignature(invoker.getInterface(), name, types);
                  Class<?>[] params = method.getParameterTypes();
                  if (args == null) {
                      args = new Object[params.length];
                  }
  
                  if(types == null) {
                      types = new String[params.length];
                  }
  
                  if (args.length != types.length) {
                      throw new RpcException("GenericFilter#invoke args.length != types.length, please check your "
                              + "params");
                  }
                  String generic = inv.getAttachment(GENERIC_KEY);
  
                  if (StringUtils.isBlank(generic)) {
                      generic = RpcContext.getContext().getAttachment(GENERIC_KEY);
                  }
  
                  if (StringUtils.isEmpty(generic)
                          || ProtocolUtils.isDefaultGenericSerialization(generic)
                          || ProtocolUtils.isGenericReturnRawResult(generic)) {
                      args = PojoUtils.realize(args, params, method.getGenericParameterTypes());
                  } else if (ProtocolUtils.isJavaGenericSerialization(generic)) {
                      for (int i = 0; i < args.length; i++) {
                          if (byte[].class == args[i].getClass()) {
                              try (UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream((byte[]) args[i])) {
                                  args[i] = ExtensionLoader.getExtensionLoader(Serialization.class)
                                          .getExtension(GENERIC_SERIALIZATION_NATIVE_JAVA)
                                          .deserialize(null, is).readObject();
                              } catch (Exception e) {
                                  throw new RpcException("Deserialize argument [" + (i + 1) + "] failed.", e);
                              }
                          } else {
                              throw new RpcException(
                                      "Generic serialization [" +
                                              GENERIC_SERIALIZATION_NATIVE_JAVA +
                                              "] only support message type " +
                                              byte[].class +
                                              " and your message type is " +
                                              args[i].getClass());
                          }
                      }
                  } else if (ProtocolUtils.isBeanGenericSerialization(generic)) {
                      for (int i = 0; i < args.length; i++) {
                          if (args[i] instanceof JavaBeanDescriptor) {
                              args[i] = JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) args[i]);
                          } else {
                              throw new RpcException(
                                      "Generic serialization [" +
                                              GENERIC_SERIALIZATION_BEAN +
                                              "] only support message type " +
                                              JavaBeanDescriptor.class.getName() +
                                              " and your message type is " +
                                              args[i].getClass().getName());
                          }
                      }
                  } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) {
                      // as proto3 only accept one protobuf parameter
                      if (args.length == 1 && args[0] instanceof String) {
                          try (UnsafeByteArrayInputStream is =
                                       new UnsafeByteArrayInputStream(((String) args[0]).getBytes())) {
                              args[0] = ExtensionLoader.getExtensionLoader(Serialization.class)
                                      .getExtension(GENERIC_SERIALIZATION_PROTOBUF)
                                      .deserialize(null, is).readObject(method.getParameterTypes()[0]);
                          } catch (Exception e) {
                              throw new RpcException("Deserialize argument failed.", e);
                          }
                      } else {
                          throw new RpcException(
                                  "Generic serialization [" +
                                          GENERIC_SERIALIZATION_PROTOBUF +
                                          "] only support one " + String.class.getName() +
                                          " argument and your message size is " +
                                          args.length + " and type is" +
                                          args[0].getClass().getName());
                      }
                  }
  
                  RpcInvocation rpcInvocation = new RpcInvocation(method, invoker.getInterface().getName(), invoker.getUrl().getProtocolServiceKey(), args, inv.getObjectAttachments(), inv.getAttributes());
                  rpcInvocation.setInvoker(inv.getInvoker());
                  rpcInvocation.setTargetServiceUniqueName(inv.getTargetServiceUniqueName());
  
                  return invoker.invoke(rpcInvocation);
              } catch (NoSuchMethodException | ClassNotFoundException e) {
                  throw new RpcException(e.getMessage(), e);
              }
          }
          return invoker.invoke(inv);
      }
focal_method.class_method_signature: GenericFilter.invoke(Invoker<?> invoker, Invocation inv)
focal_method.full_signature: @Override public Result invoke(Invoker<?> invoker, Invocation inv)
focal_method.identifier: invoke
focal_method.invocations: equals getMethodName equals getMethodName getArguments getArguments isAssignableFrom getInterface trim getArguments getArguments getArguments findMethodByMethodSignature getInterface getParameterTypes getAttachment isBlank getAttachment getContext isEmpty isDefaultGenericSerialization isGenericReturnRawResult realize getGenericParameterTypes isJavaGenericSerialization getClass readObject deserialize getExtension getExtensionLoader getClass isBeanGenericSerialization deserialize getName getName getClass isProtobufGenericSerialization getBytes readObject deserialize getExtension getExtensionLoader getParameterTypes getName getName getClass getName getInterface getProtocolServiceKey getUrl getObjectAttachments getAttributes setInvoker getInvoker setTargetServiceUniqueName getTargetServiceUniqueName invoke getMessage invoke
focal_method.modifiers: @Override public
focal_method.parameters: (Invoker<?> invoker, Invocation inv)
focal_method.return: Result
focal_method.signature: Result invoke(Invoker<?> invoker, Invocation inv)