FasterXML / FasterXML/jackson-modules-base

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

Open
#51 7 comments 0 reactions 0 assignees View on GitHub
afterburner need-test-case
Dominant language
Java
Stars
180
Forks
80
Avg merge
3h 26m
Merged PRs (30d)
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.