question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JDK 16 Illegal reflective access for `Throwable.setCause()` with `PropertyNamingStrategy.UPPER_CAMEL_CASE`

See original GitHub issue

Describe the bug Mapping a json string to an instance of RuntimeException with JDK 16 (which defaults to denying illegal reflective access) while using UPPER_CAMEL_CASE property naming strategy, fails with:

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Failed to call `setAccess()` on Method 'setCause' due to `java.lang.reflect.InaccessibleObjectException`, problem: Unable to make final void java.lang.Throwable.setCause(java.lang.Throwable) accessible: module java.base does not "opens java.lang" to unnamed module

This manifests in parts of the AWS v1 SDK when an error is received from the AWS API endpoints. Note example report: https://github.com/FasterXML/jackson-databind/issues/2464#issuecomment-856996757

The simplified reproduce case below is based on what the failing AWS SDK code is doing internally in com.amazonaws.transform.JsonErrorUnmarshaller.unmarshall.

Version information 2.12.3, 2.12.5, 2.13.0-rc2

To Reproduce Execute this code without any --add-opens params and with default --illegal-access setting of deny.

public class Test {
	public static void main(String[] args) throws Exception {
		ObjectMapper mapper = new ObjectMapper();
		mapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);

		String jsonString = "{\"message\":\"This is my runtime exception message\"}";
		JsonNode jsonContent = mapper.readTree(jsonString);

		throw mapper.treeToValue(jsonContent, RuntimeException.class);
	}
}

Expected behavior It is expected that the code above would throw a RuntimeException with a message of “This is my runtime exception message”. This is what happens when working around the issue with java parameter --add-opens java.base/java.lang=ALL-UNNAMED

Additional context Using java parameter --illegal-access=debug results in the following additional info:

WARNING: Illegal reflective access by com.fasterxml.jackson.databind.util.ClassUtil (file:/xxxxxx/jackson-databind-2.13.0-rc2.jar) to method java.lang.Throwable.setCause(java.lang.Throwable)
	at com.fasterxml.jackson.databind.util.ClassUtil.checkAndFixAccess(ClassUtil.java:994)
	at com.fasterxml.jackson.databind.introspect.AnnotatedMember.fixAccess(AnnotatedMember.java:139)
	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.fixAccess(MethodProperty.java:95)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder._fixAccess(BeanDeserializerBuilder.java:522)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder.build(BeanDeserializerBuilder.java:373)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildThrowableDeserializer(BeanDeserializerFactory.java:455)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:112)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:415)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:350)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
	at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:642)
	at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4751)
	at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:4596)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2815)
	at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:3279)
	at Test.main(Test.java:13)

Note that the issue does not manifest without mapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
cowtowncodercommented, May 25, 2022

@yawkat Ok. Just didn’t see it in JDK javadocs; I guess only public (and maybe protected methods are included).

@gsinghlulu yes, correct on both accounts. I think fix is along the right lines; will see if we could first remove setCause() if it exists (or replace it). I am only hesitant about looking at Cause in case other translations might miss it. But it might be good enough too, either way thank you for providing it!

1reaction
cowtowncodercommented, May 26, 2022

Ok, yes, JDK 12 added Throwable.setCause() apparently.

This specific issue now fixed in 2.13 (for 2.13.4, then 2.14.0). But I think there is the follow-up issue of PropertyNamingStrategy not working for Throwable, will file separate issue for that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning on Illegal reflective access by com.fasterxml.jackson ...
I am getting the below warning intermittently while running my java application, WARNING: All illegal access operations will be denied in a ...
Read more >
Java 9 Illegal Reflective Access Warning - Baeldung
In this tutorial, we'll inspect the relationship between the module system and reflection. 2. Modular System and Reflection.
Read more >
Illegal access in Java 16 A.K.A. 'My program crashes!'
The dreaded deep reflection tries to make everything visible to client code, no matter if the author of the object wanted some parts...
Read more >
A peek into Java 17: Encapsulating the Java runtime internals
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by ReflBytecodeName ...
Read more >
subject:"\[jackson\-user\] Illegal reflective access warning in JDK 12"
fasterxml.jackson.databind.util.ClassUtil (...) to method > java.lang.Throwable.setCause(java.lang.Throwable) > > WARNING: Please consider reporting this to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found