mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-24 03:10:14 +08:00
static final field is not assignable during runtime
This commit is contained in:
parent
75c6a67b8f
commit
5f6cf3888c
@ -27,12 +27,13 @@ public class OmniClassHandler extends BaseClassHandler {
|
||||
private static final String ENABLE_CONFIGURATION = "Lorg/springframework/context/annotation/Configuration;";
|
||||
private static final String CLASS_ABSTRACT_COLLECTION = "java/util/AbstractCollection";
|
||||
private static final String CLASS_NUMBER = "java/lang/Number";
|
||||
private static final String CLASS_HASH_SET = "java/util/HashSet";
|
||||
|
||||
private static final String[] JUNIT_TEST_ANNOTATIONS = new String[] {
|
||||
JUnit4Framework.ANNOTATION_TEST, JUnit5Framework.ANNOTATION_TEST, JUnit5Framework.ANNOTATION_PARAMETERIZED_TEST
|
||||
};
|
||||
private static final String[] UNREACHABLE_CLASSES = new String[] {
|
||||
CLASS_ABSTRACT_COLLECTION, CLASS_NUMBER
|
||||
CLASS_ABSTRACT_COLLECTION, CLASS_NUMBER, CLASS_HASH_SET
|
||||
};
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,9 @@ package com.alibaba.testable.core.model;
|
||||
|
||||
public enum ConstructionOption {
|
||||
|
||||
/**
|
||||
* allow members with same type nested inside itself be initialized as null
|
||||
*/
|
||||
ALLOW_NULL_FOR_NESTED_TYPE
|
||||
|
||||
}
|
||||
|
@ -60,6 +60,8 @@ public class OmniConstructor {
|
||||
try {
|
||||
if (clazz.isPrimitive()) {
|
||||
return newPrimitive(clazz);
|
||||
} else if (clazz.equals(Class.class)) {
|
||||
return (T)Object.class;
|
||||
} else if (clazz.isArray()) {
|
||||
return (T)newArray(clazz.getComponentType(), 0, classPool);
|
||||
} else if (clazz.isEnum()) {
|
||||
@ -176,8 +178,8 @@ public class OmniConstructor {
|
||||
LogUtil.verbose(classPool.size(), "Verifying %s", type.getName());
|
||||
classPool.put(type, instance);
|
||||
for (Field f : TypeUtil.getAllFields(type)) {
|
||||
if (f.getName().startsWith("$")) {
|
||||
// skip fields e.g. "$jacocoData"
|
||||
if (f.getName().startsWith("$") || isStaticFinalField(f)) {
|
||||
// skip static-final fields and fields e.g. "$jacocoData"
|
||||
continue;
|
||||
}
|
||||
f.setAccessible(true);
|
||||
@ -201,6 +203,10 @@ public class OmniConstructor {
|
||||
classPool.remove(type);
|
||||
}
|
||||
|
||||
private static boolean isStaticFinalField(Field field) {
|
||||
return Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers());
|
||||
}
|
||||
|
||||
private static void handleCircleReferenceOfArrayField(Object instance, Class<?> type, Map<Class<?>, Object> classPool)
|
||||
throws IllegalAccessException {
|
||||
if (type.isArray()) {
|
||||
|
Loading…
Reference in New Issue
Block a user