mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-02-03 16:20:54 +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 ENABLE_CONFIGURATION = "Lorg/springframework/context/annotation/Configuration;";
|
||||||
private static final String CLASS_ABSTRACT_COLLECTION = "java/util/AbstractCollection";
|
private static final String CLASS_ABSTRACT_COLLECTION = "java/util/AbstractCollection";
|
||||||
private static final String CLASS_NUMBER = "java/lang/Number";
|
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[] {
|
private static final String[] JUNIT_TEST_ANNOTATIONS = new String[] {
|
||||||
JUnit4Framework.ANNOTATION_TEST, JUnit5Framework.ANNOTATION_TEST, JUnit5Framework.ANNOTATION_PARAMETERIZED_TEST
|
JUnit4Framework.ANNOTATION_TEST, JUnit5Framework.ANNOTATION_TEST, JUnit5Framework.ANNOTATION_PARAMETERIZED_TEST
|
||||||
};
|
};
|
||||||
private static final String[] UNREACHABLE_CLASSES = new String[] {
|
private static final String[] UNREACHABLE_CLASSES = new String[] {
|
||||||
CLASS_ABSTRACT_COLLECTION, CLASS_NUMBER
|
CLASS_ABSTRACT_COLLECTION, CLASS_NUMBER, CLASS_HASH_SET
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,9 @@ package com.alibaba.testable.core.model;
|
|||||||
|
|
||||||
public enum ConstructionOption {
|
public enum ConstructionOption {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* allow members with same type nested inside itself be initialized as null
|
||||||
|
*/
|
||||||
ALLOW_NULL_FOR_NESTED_TYPE
|
ALLOW_NULL_FOR_NESTED_TYPE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,8 @@ public class OmniConstructor {
|
|||||||
try {
|
try {
|
||||||
if (clazz.isPrimitive()) {
|
if (clazz.isPrimitive()) {
|
||||||
return newPrimitive(clazz);
|
return newPrimitive(clazz);
|
||||||
|
} else if (clazz.equals(Class.class)) {
|
||||||
|
return (T)Object.class;
|
||||||
} else if (clazz.isArray()) {
|
} else if (clazz.isArray()) {
|
||||||
return (T)newArray(clazz.getComponentType(), 0, classPool);
|
return (T)newArray(clazz.getComponentType(), 0, classPool);
|
||||||
} else if (clazz.isEnum()) {
|
} else if (clazz.isEnum()) {
|
||||||
@ -176,8 +178,8 @@ public class OmniConstructor {
|
|||||||
LogUtil.verbose(classPool.size(), "Verifying %s", type.getName());
|
LogUtil.verbose(classPool.size(), "Verifying %s", type.getName());
|
||||||
classPool.put(type, instance);
|
classPool.put(type, instance);
|
||||||
for (Field f : TypeUtil.getAllFields(type)) {
|
for (Field f : TypeUtil.getAllFields(type)) {
|
||||||
if (f.getName().startsWith("$")) {
|
if (f.getName().startsWith("$") || isStaticFinalField(f)) {
|
||||||
// skip fields e.g. "$jacocoData"
|
// skip static-final fields and fields e.g. "$jacocoData"
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
@ -201,6 +203,10 @@ public class OmniConstructor {
|
|||||||
classPool.remove(type);
|
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)
|
private static void handleCircleReferenceOfArrayField(Object instance, Class<?> type, Map<Class<?>, Object> classPool)
|
||||||
throws IllegalAccessException {
|
throws IllegalAccessException {
|
||||||
if (type.isArray()) {
|
if (type.isArray()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user