diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SubstituteOnlyIfPresent.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SubstituteOnlyIfPresent.java new file mode 100644 index 0000000000..e943ff2e0f --- /dev/null +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/SubstituteOnlyIfPresent.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.orm.jpa.vendor; + +import java.util.function.Predicate; + +/** + * Predicate intended to enabled the related GraalVM substitution only when the class is present in the classpath. + * + * @author Sebastien Deleuze + * @since 6.1 + */ +class SubstituteOnlyIfPresent implements Predicate { + + @Override + public boolean test(String type) { + try { + Class.forName(type, false, getClass().getClassLoader()); + return true; + } + catch (ClassNotFoundException | NoClassDefFoundError ex) { + return false; + } + } +} diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java index 7da52126ae..62d31f12f6 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProvider.java @@ -31,7 +31,7 @@ import org.hibernate.property.access.spi.PropertyAccess; * @author Sebastien Deleuze * @since 6.1 */ -@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl") +@TargetClass(className = "org.hibernate.bytecode.internal.none.BytecodeProviderImpl", onlyWith = SubstituteOnlyIfPresent.class) final class Target_BytecodeProvider { @Substitute diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java index c774a95823..c2c767afc9 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/Target_BytecodeProviderInitiator.java @@ -32,7 +32,7 @@ import static com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; * @author Sebastien Deleuze * @since 6.1 */ -@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator") +@TargetClass(className = "org.hibernate.bytecode.internal.BytecodeProviderInitiator", onlyWith = SubstituteOnlyIfPresent.class) final class Target_BytecodeProviderInitiator { @Alias