Fix autovalue class loading in karaf

When Class.forName is called for a class in a different bundle it will
fail as the default karaf class loader won't load classes from other
bundles.

I have fixed this by using the classloader of the original
(non-autovalue) type and assuming it will be in the same bundle as the
autovalue type (I think this is a reasonable assumtion).

So far the only place where I've actually seen this being an issue is
when using the jclouds-labs-google provider within karaf. It fails
when serialising the Firewall.Rule class within a FirewallOptions
object.
This commit is contained in:
Duncan Grant 2016-09-05 09:40:48 +01:00 committed by Ignasi Barrera
parent 3b42bafe25
commit 7aad599721
1 changed files with 1 additions and 1 deletions

View File

@ -132,7 +132,7 @@ public final class DeserializationConstructorAndReflectiveTypeAdapterFactory imp
String autoClassName = type.getRawType().getName().replace('$', '_')
.replace(packageName + ".", packageName + ".AutoValue_");
try {
type = (TypeToken<T>) TypeToken.get(Class.forName(autoClassName));
type = (TypeToken<T>) TypeToken.get(type.getRawType().getClassLoader().loadClass(autoClassName));
} catch (ClassNotFoundException ignored) {
}
}