Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isAnnotationPresent on some android devices throws NoClassDefFoundError (fix attached) #218

Closed
amiton opened this issue May 14, 2014 · 4 comments

Comments

@amiton
Copy link
Contributor

amiton commented May 14, 2014

isAnnotationPresent on some android devices throws NoClassDefFoundError if some unrelated annotation cannot be found so my code change suggests to allow users to override the behaviour by separating to another function (also makes code cleaner).
Please accept my code change to the master branch (diff below).

diff --git a/src/com/esotericsoftware/kryo/Kryo.java b/src/com/esotericsoftware/kryo/Kryo.java
index b04aa07..9ff2e87 100644
--- a/src/com/esotericsoftware/kryo/Kryo.java
+++ b/src/com/esotericsoftware/kryo/Kryo.java
@@ -328,10 +328,8 @@ public class Kryo {
        public Serializer getDefaultSerializer (Class type) {
                if (type == null) throw new IllegalArgumentException("type cannot be null.");

-               if (type.isAnnotationPresent(DefaultSerializer.class)) {
-                       DefaultSerializer defaultSerializerAnnotation = (DefaultSerializer)type.getAnnotation(DefaultSerializer.class);
-                       return ReflectionSerializerFactory.makeSerializer(this, defaultSerializerAnnotation.value(), type);
-               }
+               final Serializer serializerForAnnotation = getDefaultSerializerForAnnotatedType(type);
+               if (serializerForAnnotation!=null) return serializerForAnnotation;

                for (int i = 0, n = defaultSerializers.size(); i < n; i++) {
                        DefaultSerializerEntry entry = defaultSerializers.get(i);
@@ -344,6 +342,16 @@ public class Kryo {
                return newDefaultSerializer(type);
        }

+       protected Serializer getDefaultSerializerForAnnotatedType(Class type)
+       {
+               if (type.isAnnotationPresent(DefaultSerializer.class)) {
+                       DefaultSerializer defaultSerializerAnnotation = (DefaultSerializer)type.getAnnotation(DefaultSerializer.class);
+                       return ReflectionSerializerFactory.makeSerializer(this, defaultSerializerAnnotation.value(), type);
+               }
+
+               return null;    
+       }
@amiton
Copy link
Contributor Author

amiton commented May 22, 2014

Any updates on this?
What should i do to get this diff approved/committed?

Thanks,

@romix
Copy link
Collaborator

romix commented May 22, 2014

In principle, I don't have anything against it. Could you submit it as a PR (pull request), so that it is easier for us to merge?

@amiton
Copy link
Contributor Author

amiton commented May 22, 2014

Done. Please review my pull request and approve.
Thanks for the quick reply and great work.

romix added a commit that referenced this issue May 22, 2014
Per romix's request regarding issue #218 here is the changed code via pull request
@romix
Copy link
Collaborator

romix commented May 22, 2014

Merged. Thanks!

@romix romix closed this as completed May 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants