Translate

2015년 5월 11일 월요일

[Android] java.lang.IncompatibleClassChangeError: Couldn't find 이슈




Lib: Gson v2.3.1


Lollipop 이 출시가 되고 삼성 단말에서 ANR과 함께 아래와 같은 로그가 발생했다.


??-?? ??:??:??  3048  8514 E AndroidRuntime: FATAL EXCEPTION: Thread-1548
??-?? ??:??:??  3048  8514 E AndroidRuntime: Process: com.???.????????, PID: 3048
??-?? ??:??:??  3048  8514 E AndroidRuntime: java.lang.IncompatibleClassChangeError: Couldn't find com.google.gson.annotations.SerializedName.value
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:659)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at java.lang.reflect.Field.getAnnotation(Field.java:242)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:71)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapterFactory.java:67)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.Gson.getAdapter(Gson.java:359)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:809)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:775)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:724)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.google.gson.Gson.fromJson(Gson.java:696)
??-?? ??:??:??  3048  8514 E AndroidRuntime:    at com.???.?????????.run(?????.java:302) 




에러가 발생한 부분은 다음과 같다.
https://android.googlesource.com/platform/libcore/+/android-5.0.2_r3/luni/src/main/java/libcore/reflect/AnnotationAccess.java

private static <A extends Annotation> A toAnnotationInstance(Class<?> context, Dex dex,
        Class<A> annotationClass, EncodedValueReader reader) {
    int fieldCount = reader.readAnnotation();
    if (annotationClass != context.getDexCacheType(dex, reader.getAnnotationType())) {
        throw new AssertionError("annotation value type != return type");
    }
    AnnotationMember[] members = new AnnotationMember[fieldCount];
    for (int i = 0; i < fieldCount; i++) {
        int name = reader.readAnnotationName();
        String nameString = dex.strings().get(name);
        Method method;
        try {
            method = annotationClass.getMethod(nameString, NO_ARGUMENTS);
        } catch (NoSuchMethodException e) {
            throw new IncompatibleClassChangeError(
                    "Couldn't find " + annotationClass.getName() + "." + nameString);
        }
        Class<?> returnType = method.getReturnType();
        Object value = decodeValue(context, returnType, dex, reader);
        members[i] = new AnnotationMember(nameString, value, returnType, method);
    }
    return AnnotationFactory.createAnnotation(annotationClass, members);
}





Lollipop 에서 Memory 이슈가 많던데..
아마 이것도 Garbage Collection 문제가 아닐까 싶다.

https://code.google.com/p/android/issues/detail?id=172339
http://jackson-users.ning.com/forum/topics/android-jackson-parsing-using-annotations
http://stackoverflow.com/questions/29619052/how-to-fix-incompatibleclasschangeerror-during-android-jackson-parsing-using-ann


위의 링크를 보면 모두 Lollipop 에서만 문제가 발생하고 있으며
Samsung Device 에서만 발생한다는 답변도 보인다.



처음에는 네트워크 불안한문제나 우리의 로직에 문제가 있지 않을까 싶었는데..
Lollipop 이슈로 결론을 짓고 AssertionError, IncompatibleClassChangeError 에 대한 예외처리를 따로 하는게 맞을 듯 싶다.


댓글 없음 :

댓글 쓰기