Harden detection of InaccessibleObjectException in MetadataUtil (#1766)
The immediate cause under JDK16+ is not always InaccessibleObjectException meaning the fallback logic to copy properties does not kick in. Additional logic is needed to harden the detection of the InaccessibleObjectException to ensure it is catered for in the fallback logic. Co-authored-by: Adrian Hjertstedt <adrian@adrianhj.com>
This commit is contained in:
committed by
GitHub
parent
036715022f
commit
ce03ee008b
@@ -33,6 +33,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
||||
import com.fasterxml.jackson.databind.ser.FilterProvider;
|
||||
import com.fasterxml.jackson.databind.ser.PropertyWriter;
|
||||
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
|
||||
@@ -93,7 +94,9 @@ public final class MetadataUtil {
|
||||
return MAPPER.readerForUpdating(objectToMerge).readValue(bytes);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e.getClass().toString().contains("InaccessibleObjectException")) {
|
||||
if (e.getClass().toString().contains("InaccessibleObjectException")
|
||||
|| (e instanceof InvalidDefinitionException
|
||||
&& e.getMessage().contains("InaccessibleObjectException"))) {
|
||||
// JDK 16 workaround - ObjectMapper seems not be JDK16 compatible
|
||||
// with the setup present in Spring Cloud Contract. So we will not
|
||||
// allow patching but we will just copy values from the patch to
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.contract.verifier.messaging.amqp
|
||||
|
||||
import com.rabbitmq.client.Channel
|
||||
import org.mockito.exceptions.verification.WantedButNotInvoked
|
||||
import spock.lang.IgnoreIf
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.amqp.core.Binding
|
||||
@@ -41,7 +40,6 @@ import static org.springframework.amqp.support.converter.DefaultClassMapper.DEFA
|
||||
/**
|
||||
* @author Mathias Düsterhöft
|
||||
*/
|
||||
@IgnoreIf({ jvm.isJava17Compatible() })
|
||||
class SpringAmqpStubMessagesSpec extends Specification {
|
||||
|
||||
RabbitTemplate rabbitTemplate = mock(RabbitTemplate.class)
|
||||
|
||||
@@ -19,8 +19,6 @@ package org.springframework.cloud.contract.verifier.messaging.amqp;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@@ -28,7 +26,6 @@ class AmqpMetadataTests {
|
||||
|
||||
YAMLMapper mapper = new YAMLMapper();
|
||||
|
||||
@DisabledOnJre(JRE.JAVA_17)
|
||||
@Test
|
||||
void should_parse_the_metadata_entry() throws JsonProcessingException {
|
||||
// @formatter:off
|
||||
|
||||
Reference in New Issue
Block a user