From 3354337bec6f4276572da381a86e3e52cdc0f431 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 15 Mar 2021 11:42:30 +0000 Subject: [PATCH] Fix Forbidden API warning about Class#newInstance() being deprecated in Java 15 --- .../orm/runtime/boot/FastBootMetadataBuilder.java | 5 +++-- .../orm/runtime/boot/RecordableBootstrapFactory.java | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java index 44ea98d385395..05353c01bffe4 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java @@ -19,6 +19,7 @@ import static org.hibernate.jpa.AvailableSettings.COLLECTION_CACHE_PREFIX; import static org.hibernate.jpa.AvailableSettings.PERSISTENCE_UNIT_NAME; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -603,8 +604,8 @@ private void applyMetadataBuilderContributor() { if (metadataBuilderContributorImplClass != null) { try { - metadataBuilderContributor = metadataBuilderContributorImplClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + metadataBuilderContributor = metadataBuilderContributorImplClass.getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalArgumentException("The MetadataBuilderContributor class [" + metadataBuilderContributorImplClass + "] could not be instantiated!", e); } diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/RecordableBootstrapFactory.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/RecordableBootstrapFactory.java index 26ddc5648c327..13dce20f0ac6b 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/RecordableBootstrapFactory.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/RecordableBootstrapFactory.java @@ -1,5 +1,7 @@ package io.quarkus.hibernate.orm.runtime.boot; +import java.lang.reflect.InvocationTargetException; + import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl; @@ -51,9 +53,10 @@ private static InitialInitiatorListProvider initReactiveListProviderMaybe() { //Use reflection as we don't want the Hibernate ORM extension to depend on the Hibernate Reactive extension: final Class forName = Class .forName("io.quarkus.hibernate.reactive.runtime.boot.registry.ReactiveHibernateInitiatorListProvider"); - final Object o = forName.newInstance(); + final Object o = forName.getDeclaredConstructor().newInstance(); return (InitialInitiatorListProvider) o; - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException + | InvocationTargetException e) { //Be silent as this is a static initializer: most likely the Hibernate Reactive extension is //not on the classpath, which implies we won't need this. return null;