From 81e61cc5c3d83b716ca2e712ccdc444c0fff208a Mon Sep 17 00:00:00 2001 From: jimin Date: Thu, 20 Jun 2019 07:01:24 +0800 Subject: [PATCH 1/4] remove unnecessary null check before instance of (#4321) Signed-off-by: jimin.jm --- .../dubbo/common/beanutil/JavaBeanSerializeUtil.java | 4 ++-- .../java/org/apache/dubbo/common/json/JSONArray.java | 10 +++++----- .../java/org/apache/dubbo/common/json/JSONObject.java | 10 +++++----- .../dubbo/registry/support/ProviderInvokerWrapper.java | 2 +- .../dubbo/remoting/transport/netty/NettyHelper.java | 2 +- .../protocol/dubbo/decode/DubboTelnetDecodeTest.java | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java index 995965ac74a..1ce5c455cf5 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java @@ -237,12 +237,12 @@ private static void deserializeInternal(Object result, JavaBeanDescriptor beanDe for (Map.Entry entry : beanDescriptor) { Object key = entry.getKey(); Object value = entry.getValue(); - if (key != null && key instanceof JavaBeanDescriptor) { + if (key instanceof JavaBeanDescriptor) { JavaBeanDescriptor keyDescriptor = (JavaBeanDescriptor) entry.getKey(); key = instantiateForDeserialize(keyDescriptor, loader, cache); deserializeInternal(key, keyDescriptor, loader, cache); } - if (value != null && value instanceof JavaBeanDescriptor) { + if (value instanceof JavaBeanDescriptor) { JavaBeanDescriptor valueDescriptor = (JavaBeanDescriptor) entry.getValue(); value = instantiateForDeserialize(valueDescriptor, loader, cache); deserializeInternal(value, valueDescriptor, loader, cache); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java index f5e039c3be8..a75bedbdd40 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java @@ -47,7 +47,7 @@ public Object get(int index) { */ public boolean getBoolean(int index, boolean def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Boolean ? ((Boolean) tmp).booleanValue() : def; + return tmp instanceof Boolean ? ((Boolean) tmp).booleanValue() : def; } /** @@ -59,7 +59,7 @@ public boolean getBoolean(int index, boolean def) { */ public int getInt(int index, int def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).intValue() : def; + return tmp instanceof Number ? ((Number) tmp).intValue() : def; } /** @@ -71,7 +71,7 @@ public int getInt(int index, int def) { */ public long getLong(int index, long def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).longValue() : def; + return tmp instanceof Number ? ((Number) tmp).longValue() : def; } /** @@ -83,7 +83,7 @@ public long getLong(int index, long def) { */ public float getFloat(int index, float def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).floatValue() : def; + return tmp instanceof Number ? ((Number) tmp).floatValue() : def; } /** @@ -95,7 +95,7 @@ public float getFloat(int index, float def) { */ public double getDouble(int index, double def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).doubleValue() : def; + return tmp instanceof Number ? ((Number) tmp).doubleValue() : def; } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java index 052f35269dd..c04d4e14050 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java @@ -47,7 +47,7 @@ public Object get(String key) { */ public boolean getBoolean(String key, boolean def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Boolean ? (Boolean) tmp : def; + return tmp instanceof Boolean ? (Boolean) tmp : def; } /** @@ -59,7 +59,7 @@ public boolean getBoolean(String key, boolean def) { */ public int getInt(String key, int def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).intValue() : def; + return tmp instanceof Number ? ((Number) tmp).intValue() : def; } /** @@ -71,7 +71,7 @@ public int getInt(String key, int def) { */ public long getLong(String key, long def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).longValue() : def; + return tmp instanceof Number ? ((Number) tmp).longValue() : def; } /** @@ -83,7 +83,7 @@ public long getLong(String key, long def) { */ public float getFloat(String key, float def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).floatValue() : def; + return tmp instanceof Number ? ((Number) tmp).floatValue() : def; } /** @@ -95,7 +95,7 @@ public float getFloat(String key, float def) { */ public double getDouble(String key, double def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).doubleValue() : def; + return tmp instanceof Number ? ((Number) tmp).doubleValue() : def; } /** diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java index ce079b743e4..a1eaad3410d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java @@ -90,7 +90,7 @@ public void setReg(boolean reg) { @Override public boolean equals(Object o) { - if (o == null || !(o instanceof ProviderInvokerWrapper)) { + if (!(o instanceof ProviderInvokerWrapper)) { return false; } ProviderInvokerWrapper other = (ProviderInvokerWrapper) o; diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java index ec73094ce95..64f41b2daef 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java @@ -27,7 +27,7 @@ final class NettyHelper { public static void setNettyLoggerFactory() { InternalLoggerFactory factory = InternalLoggerFactory.getDefaultFactory(); - if (factory == null || !(factory instanceof DubboLoggerFactory)) { + if (!(factory instanceof DubboLoggerFactory)) { InternalLoggerFactory.setDefaultFactory(new DubboLoggerFactory()); } } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java index e54d2e6508a..28c49cce497 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java @@ -452,7 +452,7 @@ private ByteBuf createDubboByteBuf() throws IOException { } private static boolean checkTelnetDecoded(Object msg) { - if (msg != null && msg instanceof String && !msg.toString().contains("Unsupported command:")) { + if (msg instanceof String && !msg.toString().contains("Unsupported command:")) { return true; } return false; From 60c9d9dbbc8db2dccc019df82d7a9194d4ccbdfa Mon Sep 17 00:00:00 2001 From: zhenxianyimeng <1920405993@qq.com> Date: Thu, 20 Jun 2019 07:02:59 +0800 Subject: [PATCH 2/4] add zookeeper maven dependency so that on change registery can run the demo (#4352) --- .../dubbo-demo-annotation-consumer/pom.xml | 8 ++++++++ .../dubbo-demo-annotation-provider/pom.xml | 8 ++++++++ dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml | 8 ++++++++ dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml index c13bc265bc2..c8f9d9d50e1 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml @@ -42,6 +42,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-rpc-dubbo diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml index 4f164bce61e..02d0248e431 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml @@ -43,6 +43,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-rpc-dubbo diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml index 4dfde790cfa..5720551e7db 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml @@ -38,6 +38,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-config-spring diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml index a93c41ccf00..c683235834a 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml @@ -40,6 +40,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-rpc-dubbo From fa619c9842113ca320e0f72050987f77a6c7f92f Mon Sep 17 00:00:00 2001 From: Huang YunKun Date: Fri, 21 Jun 2019 08:43:27 +0800 Subject: [PATCH 3/4] [Dubbo-4355] Fix dubbo.jar do not contain "serialization-protobuf-json" module issue (#4356) (#4364) * include protobuf-json jar to dubbo --- dubbo-all/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index d8c8949c13e..eaa2dbc92ea 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -622,7 +622,7 @@ org.apache.dubbo:dubbo-serialization-jdk org.apache.dubbo:dubbo-serialization-protostuff org.apache.dubbo:dubbo-serialization-gson - org.apache.dubbo:dubbo-serialization-googlePb + org.apache.dubbo:dubbo-serialization-protobuf-json org.apache.dubbo:dubbo-configcenter-api org.apache.dubbo:dubbo-configcenter-definition org.apache.dubbo:dubbo-configcenter-apollo From 7285ce9bf2ed8ec56d06fb0b3c7b0f1d7aa81192 Mon Sep 17 00:00:00 2001 From: HzjNeverStop <441627022@qq.com> Date: Mon, 24 Jun 2019 21:21:10 +0800 Subject: [PATCH 4/4] [Dubbo-4299]Fix NPE when PojoUtils realize Null element in collection(#4299) (#4300) * fix NPE when PojoUtils realize Null element in collection(#4299) * add unit tests for bugfix of PojoUtils NPE(#4299) * revert import (#4299) --- .../apache/dubbo/common/utils/PojoUtils.java | 2 +- .../dubbo/common/utils/PojoUtilsTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java index 3bab26134e3..52204acb4dd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java @@ -366,7 +366,7 @@ private static Object realize0(Object pojo, Class type, Type genericType, fin history.put(pojo, dest); for (Object obj : src) { Type keyType = getGenericClassByIndex(genericType, 0); - Class keyClazz = obj.getClass(); + Class keyClazz = obj == null ? null : obj.getClass(); if (keyType instanceof Class) { keyClazz = (Class) keyType; } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java index 3595efb99f6..f0ab173b4f8 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java @@ -37,6 +37,7 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.HashSet; import java.util.Map; import java.util.UUID; @@ -682,6 +683,24 @@ public void testDateTimeTimestamp() throws Exception { assertEquals(dateTimeStr, new SimpleDateFormat(dateFormat[0]).format(timestamp)); } + @Test + public void testRealizeCollectionWithNullElement() { + LinkedList listStr = new LinkedList<>(); + listStr.add("arrayValue"); + listStr.add(null); + HashSet setStr = new HashSet<>(); + setStr.add("setValue"); + setStr.add(null); + + Object listResult = PojoUtils.realize(listStr, LinkedList.class); + assertEquals(LinkedList.class, listResult.getClass()); + assertEquals(listResult, listStr); + + Object setResult = PojoUtils.realize(setStr, HashSet.class); + assertEquals(HashSet.class, setResult.getClass()); + assertEquals(setResult, setStr); + } + public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }