Skip to content

Commit

Permalink
Fix Forbidden API warning about Class#newInstance() being deprecated …
Browse files Browse the repository at this point in the history
…in Java 15
  • Loading branch information
Sanne committed Mar 15, 2021
1 parent ab390d3 commit bb57bd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bb57bd4

Please sign in to comment.