FasterXML / FasterXML/jackson-modules-base

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

Offen
#51 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
afterburner need-test-case
Vorherrschende Sprache
Java
Sterne
180
Forks
80
Ø Merge
3 Std. 26 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.