FasterXML / FasterXML/jackson-modules-base

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

Aperta
#51 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub
afterburner need-test-case
Lingua principale
Java
Stelle
180
Fork
80
Merge medio
3h 26m
PR unite (30g)
1

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.