From 2c722851fe0de41c6db6713ab1ed1330c2c863a9 Mon Sep 17 00:00:00 2001 From: abilan Date: Sat, 14 Jan 2023 13:36:01 -0500 Subject: [PATCH] GH-3990: Fix JsonPath native hint registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/spring-projects/spring-integration/issues/3990 Turns out just being on the classpath doesn’t make the type reachable. If it’s only accessed reflectively then it’s not reachable. This is exaclt what happened with our `JsonPathUtils` which is used via reflection from SpEL when that calls its method via function reference * Change `onReachableType()` logic for `com.jayway.jsonpath.JsonPath` type to `ClassUtils.isPresent()` on `JsonPathUtils` reflection hint registration. --- .../integration/aot/CoreRuntimeHints.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java b/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java index 2da6b18510..f528bab797 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,6 @@ import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.SerializationHints; -import org.springframework.aot.hint.TypeReference; import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.context.SmartLifecycle; import org.springframework.integration.aggregator.MessageGroupProcessor; @@ -66,6 +65,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.ReactiveMessageHandler; import org.springframework.messaging.support.ErrorMessage; import org.springframework.messaging.support.GenericMessage; +import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; /** @@ -96,10 +96,10 @@ class CoreRuntimeHints implements RuntimeHintsRegistrar { Pausable.class) .forEach(type -> reflectionHints.registerType(type, MemberCategory.INVOKE_PUBLIC_METHODS)); - reflectionHints.registerType(JsonPathUtils.class, - builder -> - builder.onReachableType(TypeReference.of("com.jayway.jsonpath.JsonPath")) - .withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); + + if (ClassUtils.isPresent("com.jayway.jsonpath.JsonPath", classLoader)) { + reflectionHints.registerType(JsonPathUtils.class, MemberCategory.INVOKE_PUBLIC_METHODS); + } // For #xpath() SpEL function reflectionHints.registerTypeIfPresent(classLoader, "org.springframework.integration.xml.xpath.XPathUtils",