FasterXML / FasterXML/jackson-modules-base

Can't put @JsonCreator on non-public ctor/method in signed jar

Ouverte
#51 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
afterburner need-test-case
Langage dominant
Java
Étoiles
180
Forks
80
Merge moyen
3 h 26 min
PR mergées (30 j)
1

Description

Hello,
I ran into this problem today.

(I am running 2.8.11 on all of my jackson libs, but as far as I see in the source, the problem still exists)

I have a signed jar, which contains a class whose protected constructor is annotated with @JsonCreator. During run time, I kept receiving the following:
> java.lang.IllegalAccessError: tried to access method com.preempt.common.model.policy.FirewallTriggerDescriptor.()V from class com.preempt.common.model.policy.FirewallTriggerDescriptor$Creator4JacksonDeserializer1ddd0765

I found out the following: The FirewallTriggerDescriptor class, and the dynamic Deserializer class are loaded in different ClassLoaders, and therefore the protected constructor is not accessible. The reason this happens is due to loadAndResolve in MyClassLoader. When the Deserializer class code is generated, the code attempts to load it on the parent class loader:
```java
Method method = ClassLoader.class.getDeclaredMethod("defineClass", new Class[] {String.class, byte[].class, int.class, int.class});
method.setAccessible(true);
return (Class)method.invoke(getParent(), className.getDottedName(), byteCode, 0, byteCode.length);
```

This call to [defineClass](https://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#defineClass(java.lang.String,%20byte[],%20int,%20int)) fails with a SecurityException, because the other classes in this package are signed, and this one isn't.

I can't see anyway around it. As it is, it means that Jackson can't be used with signed jars, unless all the @JsonCreator methods are defined as public.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.