Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.2' into version
Browse files Browse the repository at this point in the history
* origin/3.2: (22 commits)
  Update codecov config (apache#11582)
  metric package structure optimization (apache#11576)
  Fix compile
  Provides the public part of metrics data collection and export (apache#11522)
  [Triple] Fix boxed type methods (apache#11577)
  Bump to 3.2.0-beta.6-SNAPSHOT
  Fix synchronized in ModelEnvironment (apache#11584)
  Fix conflict
  Fix concurrent issue in scope model (apache#11525)
  Update codecov config (apache#11580)
  Set timeout value to string (apache#11565)
  Skip mapping retry if metadata config is invalid (apache#11323)
  Fix stackoverflow in SerializeSecurityConfigurator (apache#11561)
  Revert clear response operation of timeoutfilter (apache#11562)
  Fix hessian2 serializable check (apache#11573)
  feat: fix oom (apache#11571)
  Enhance serializable check option (apache#11460)
  Fix config absent when refresh (apache#11505)
  Enhance json util check (apache#11501)
  classNotFound (apache#11552)
  ...
  • Loading branch information
mytang0 committed Feb 20, 2023
2 parents aa859a2 + 62509fb commit a4833bf
Show file tree
Hide file tree
Showing 121 changed files with 1,841 additions and 860 deletions.
17 changes: 13 additions & 4 deletions .codecov.yml → codecov.yml
Expand Up @@ -13,14 +13,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
codecov:
require_ci_to_pass: false
notify:
wait_for_ci: false
coverage:
status:
# pull-requests only
patch:
default:
threshold: 0.1%
ignore:
- "dubbo-demo/.*"
- "dubbo-common/src/main/java/org/apache/dubbo/common/json/*.java" # internal JSON impl is deprecate, ignore test coverage for them
- "dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java" # Deprecated
- "dubbo-rpc/dubbo-rpc-thrift/.*"
- "**/dubbo-demo/**"
- "**/dubbo-compiler/**"
- "**/dubbo-test/**"
- "**/dubbo-compatible/**"
- "**/dubbo-native/**"
- "**/dubbo-native-plugin/**"
- "**/dubbo-common/src/main/java/org/apache/dubbo/common/json/*.java" # internal JSON impl is deprecate, ignore test coverage for them
- "**/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java" # Deprecated
- "**/dubbo-rpc/dubbo-rpc-thrift/**"
1 change: 1 addition & 0 deletions dubbo-common/pom.xml
Expand Up @@ -42,6 +42,7 @@
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down
Expand Up @@ -186,6 +186,15 @@ private int getNextId(Class<?> beanClass) {
return ConcurrentHashMapUtils.computeIfAbsent(beanNameIdCounterMap, beanClass, key -> new AtomicInteger()).incrementAndGet();
}

@SuppressWarnings("unchecked")
public <T> List<T> getBeansOfType(Class<T> type) {
List<T> currentBeans = (List<T>) registeredBeanInfos.stream().filter(beanInfo -> type.isInstance(beanInfo.instance)).map(beanInfo -> beanInfo.instance).collect(Collectors.toList());
if (parent != null) {
currentBeans.addAll(parent.getBeansOfType(type));
}
return currentBeans;
}

public <T> T getBean(Class<T> type) {
return this.getBean(null, type);
}
Expand Down
Expand Up @@ -315,7 +315,7 @@ public String getLocalMigrationRule() {
return localMigrationRule;
}

public void refreshClassLoaders() {
public synchronized void refreshClassLoaders() {
propertiesConfiguration.refresh();
loadMigrationRule();
this.globalConfiguration = null;
Expand Down
Expand Up @@ -220,7 +220,7 @@ public String getLocalMigrationRule() {
}

@Override
public void refreshClassLoaders() {
public synchronized void refreshClassLoaders() {
orderedPropertiesConfiguration.refresh();
applicationDelegate.refreshClassLoaders();
}
Expand Down
Expand Up @@ -17,11 +17,30 @@
package org.apache.dubbo.common.json.impl;

import org.apache.dubbo.common.json.JSON;
import org.apache.dubbo.common.utils.CollectionUtils;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public abstract class AbstractJSONImpl implements JSON {
@Override
public boolean isSupport() {
try {
Map<String, String> map = new HashMap<>();
map.put("json", "test");
if (!CollectionUtils.mapEquals(map, toJavaObject(toJson(map), Map.class))) {
return false;
}

List<String> list = new LinkedList<>();
list.add("json");
return CollectionUtils.equals(list, toJavaList(toJson(list), String.class));
} catch (Throwable t) {
return false;
}
}

@Override
public List<?> getList(Map<String, ?> obj, String key) {
Expand Down
Expand Up @@ -16,25 +16,13 @@
*/
package org.apache.dubbo.common.json.impl;

import org.apache.dubbo.common.utils.ClassUtils;

import com.alibaba.fastjson2.JSONWriter;

import java.lang.reflect.Type;
import java.util.List;

public class FastJson2Impl extends AbstractJSONImpl {

@Override
public boolean isSupport() {
try {
Class<?> aClass = ClassUtils.forName("com.alibaba.fastjson2.JSON");
return aClass != null;
} catch (Exception t) {
return false;
}
}

@Override
public <T> T toJavaObject(String json, Type type) {
return com.alibaba.fastjson2.JSON.parseObject(json, type);
Expand Down
Expand Up @@ -16,25 +16,13 @@
*/
package org.apache.dubbo.common.json.impl;

import org.apache.dubbo.common.utils.ClassUtils;

import com.alibaba.fastjson.serializer.SerializerFeature;

import java.lang.reflect.Type;
import java.util.List;

public class FastJsonImpl extends AbstractJSONImpl {

@Override
public boolean isSupport() {
try {
Class<?> aClass = ClassUtils.forName("com.alibaba.fastjson.JSON");
return aClass != null;
} catch (Throwable t) {
return false;
}
}

@Override
public <T> T toJavaObject(String json, Type type) {
return com.alibaba.fastjson.JSON.parseObject(json, type);
Expand Down
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.dubbo.common.json.impl;

import org.apache.dubbo.common.utils.ClassUtils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

Expand All @@ -28,16 +26,6 @@ public class GsonImpl extends AbstractJSONImpl {
// weak reference of com.google.gson.Gson, prevent throw exception when init
private volatile Object gsonCache = null;

@Override
public boolean isSupport() {
try {
Class<?> aClass = ClassUtils.forName("com.google.gson.Gson");
return aClass != null;
} catch (Throwable t) {
return false;
}
}

@Override
public <T> T toJavaObject(String json, Type type) {
return getGson().fromJson(json, type);
Expand Down
Expand Up @@ -16,30 +16,18 @@
*/
package org.apache.dubbo.common.json.impl;

import java.lang.reflect.Type;
import java.util.List;

import org.apache.dubbo.common.utils.ClassUtils;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.lang.reflect.Type;
import java.util.List;

public class JacksonImpl extends AbstractJSONImpl {

private volatile Object jacksonCache = null;

@Override
public boolean isSupport() {
try {
Class<?> aClass = ClassUtils.forName("com.fasterxml.jackson.databind.json.JsonMapper");
return aClass != null;
} catch (Throwable t) {
return false;
}
}

@Override
public <T> T toJavaObject(String json, Type type) {
try {
Expand Down
Expand Up @@ -201,4 +201,8 @@ private Class<?> loadClass0(ClassLoader classLoader, String className) throws Cl
public static DefaultSerializeClassChecker getInstance() {
return FrameworkModel.defaultModel().getBeanFactory().getBean(DefaultSerializeClassChecker.class);
}

public boolean isCheckSerializable() {
return checkSerializable;
}
}
Expand Up @@ -16,6 +16,14 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeClassLoaderListener;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
Expand All @@ -32,14 +40,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ScopeClassLoaderListener;

import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST;
import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST;
import static org.apache.dubbo.common.constants.CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL;
Expand Down Expand Up @@ -185,8 +185,9 @@ public synchronized void registerInterface(Class<?> clazz) {
return;
}

Set<Class<?>> markedClass = new HashSet<>();
Set<Type> markedClass = new HashSet<>();
markedClass.add(clazz);
checkClass(markedClass, clazz);

addToAllow(clazz.getName());

Expand Down Expand Up @@ -221,10 +222,17 @@ public synchronized void registerInterface(Class<?> clazz) {
}
}

private void checkType(Set<Class<?>> markedClass, Type type) {
private void checkType(Set<Type> markedClass, Type type) {
if (type instanceof Class) {
checkClass(markedClass, (Class<?>) type);
} else if (type instanceof ParameterizedType) {
return;
}

if (!markedClass.add(type)) {
return;
}

if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
checkClass(markedClass, (Class<?>) parameterizedType.getRawType());
for (Type actualTypeArgument : parameterizedType.getActualTypeArguments()) {
Expand All @@ -249,13 +257,11 @@ private void checkType(Set<Class<?>> markedClass, Type type) {
}
}

private void checkClass(Set<Class<?>> markedClass, Class<?> clazz) {
if (markedClass.contains(clazz)) {
private void checkClass(Set<Type> markedClass, Class<?> clazz) {
if (!markedClass.add(clazz)) {
return;
}

markedClass.add(clazz);

addToAllow(clazz.getName());

Class<?>[] interfaces = clazz.getInterfaces();
Expand Down

0 comments on commit a4833bf

Please sign in to comment.