Skip to content

Commit

Permalink
修复GenericService实例调用非$invoke方法时有数组越界异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed Nov 23, 2020
1 parent 893c0f3 commit 610aeaa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- 完善consul,注册的服务名称默认增加分组信息,可以在注册中心URL上配置consul.serviceWithGroup=false来禁用

- Broadcast模式,支持配置广播地址参数

- Dependency

- 升级Fastjson为1.2.75版本
Expand All @@ -18,6 +20,8 @@

- 修改Springboot配置的插件可能加载不了的问题

- 修复GenericService实例调用非$invoke方法时有数组越界异常的问题

## 1.4.1-RELEASE(2020-11-05)

### Bugfixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,10 @@ protected static class ConsumerInvokeHandler implements InvocationHandler {
* The Method name hashcode.
*/
static String METHOD_NAME_HASHCODE = "hashCode";
/**
* The Method name getClass.
*/
static String METHOD_NAME_GET_CLASS = "getClass";
/**
* The Method name equals.
*/
Expand Down Expand Up @@ -979,16 +983,19 @@ public Object invoke(final Object proxy, final Method method, final Object[] par
protected Object invokeObjectMethod(final Object proxy, final Method method, final Object[] param) {
Object[] args = param;
String name = method.getName();
if (generic) {
int count = args == null ? 0 : args.length;
if (generic && count == 2) {
//判断是$asyc和$invoke方法
args = (Object[]) param[2];
name = (String) param[0];
}
int count = args == null ? 0 : args.length;
if (count == 0) {
if (METHOD_NAME_TO_STRING.equals(name)) {
return proxy.getClass().getName() + "@" + Integer.toHexString(invoker.hashCode());
} else if (METHOD_NAME_HASHCODE.equals(name)) {
return invoker.hashCode();
} else if (METHOD_NAME_GET_CLASS.equals(name)) {
return proxy.getClass();
}
} else if (count == 1 && METHOD_NAME_EQUALS.equals(name)) {
return invoker.equals(args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void main(String[] args) {
System.setProperty("spring.profiles.active", "generic");
ConfigurableApplicationContext run = SpringApplication.run(BootGeneric.class, args);
GenericService consumer = run.getBean(GenericService.class);
System.out.println(consumer.hashCode());

Map<String, Object> param = new HashMap<>();
//header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#rpc.registry.address=localhost
#rpc.registry.registry=etcd
#rpc.registry.address=localhost
#rpc.registry.registry=nacos
#rpc.registry.address=localhost
rpc.registry.registry=broadcast
#消费者
rpc.consumers[0].interfaceClazz=io.joyrpc.example.service.DemoService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ rpc.consumers[0].name=consumer-echoService
#rpc.registry.address=localhost
#rpc.registry.registry=consul
#rpc.registry.address=localhost
#rpc.registry.registry=nacos
#rpc.registry.address=localhost
rpc.registry.registry=broadcast
# app service name
rpc.parameters[appService]=myProvider
Expand Down

0 comments on commit 610aeaa

Please sign in to comment.