apache / apache/dubbo

JaketConfigurationUtils 加载方式不合理& DefaultTypeBuilder filed 多层递归问题

Open
#9,568 0 comments 0 reactions 0 assignees View on GitHub
type/discussion
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

### JaketConfigurationUtils 以固定死的目录加载配置不太合理。
```
public class JaketConfigurationUtils {
private static final String CONFIGURATION_FILE = "jaket.properties";

private static String[] includedInterfacePackages;
private static String[] includedTypePackages;
private static String[] closedTypes;

static {
Properties props = new Properties();
InputStream inStream = JaketConfigurationUtils.class.getClassLoader().getResourceAsStream(CONFIGURATION_FILE);
try {
props.load(inStream);
String value = (String) props.get("included_interface_packages");
if (StringUtils.isNotEmpty(value)) {
includedInterfacePackages = value.split(",");
}

value = props.getProperty("included_type_packages");
if (StringUtils.isNotEmpty(value)) {
includedTypePackages = value.split(",");
}

value = props.getProperty("closed_types");
if (StringUtils.isNotEmpty(value)) {
closedTypes = value.split(",");
}

} catch (Throwable e) {
// Ignore it.
}
}
}
```
DefaultTypeBuilder 对原始类型的无用递归。
```
org.apache.dubbo.metadata.definition.TypeDefinitionBuilder#build

public static TypeDefinition build(Type type, Class clazz, Map, TypeDefinition> typeCache) {
TypeBuilder builder = getGenericTypeBuilder(type, clazz);
TypeDefinition td;
if (builder != null) {
td = builder.build(type, clazz, typeCache);
td.setTypeBuilderName(builder.getClass().getName());
} else {
td = DefaultTypeBuilder.build(clazz, typeCache);
td.setTypeBuilderName(DefaultTypeBuilder.class.getName());
}
if (isSimpleType(clazz)) { // changed since 2.7.6 这里移除了原始类型的数据properties。能在DefaultTypeBuilder 里做吗?
td.setProperties(null);
}
return td;
}
---------
```
```
例如:
public final class DefaultTypeBuilder {

public static TypeDefinition build(Class clazz, Map, TypeDefinition> typeCache) {
// final String canonicalName = clazz.getCanonicalName();
final String name = clazz.getName();

TypeDefinition td = new TypeDefinition(name);
// Try to get a cached definition
if (typeCache.containsKey(clazz)) {
return typeCache.get(clazz);
}
if (isSimpleType(clazz)) {
return td;
}
// Primitive type
if (!JaketConfigurationUtils.needAnalyzing(clazz)) {
return td;
}

// Custom type
TypeDefinition ref = new TypeDefinition(name);
ref.set$ref(name);
typeCache.put(clazz, ref);

List fields = ClassUtils.getNonStaticFields(clazz);
for (Field field : fields) {
String fieldName = field.getName();
Class fieldClass = field.getType();
Type fieldType = field.getGenericType();
TypeDefinition fieldTd = TypeDefinitionBuilder.build(fieldType, fieldClass, typeCache);
td.getProperties().put(fieldName, fieldTd);
}

typeCache.put(clazz, td);
return td;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.