diff --git a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/gson/impl/AbstractConfiguredExtraPropertiesJsonAdapterFactory.java b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/gson/impl/AbstractConfiguredExtraPropertiesJsonAdapterFactory.java index a4e594a579f..691712556c4 100644 --- a/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/gson/impl/AbstractConfiguredExtraPropertiesJsonAdapterFactory.java +++ b/backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/gson/impl/AbstractConfiguredExtraPropertiesJsonAdapterFactory.java @@ -113,7 +113,7 @@ private static Constructor getConstructor(TypeToken type) { try { return (Constructor) type.getRawType().getConstructor(); } - catch (NoSuchMethodException | SecurityException e) { + catch (NoSuchMethodException e) { throw new AssertionFailure( "Missing or inaccessible no-arg constructor on type " + type ); } } diff --git a/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/ClassLoaderHelper.java b/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/ClassLoaderHelper.java index db342bca134..fdac898626e 100644 --- a/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/ClassLoaderHelper.java +++ b/engine/src/main/java/org/hibernate/search/engine/environment/classpath/spi/ClassLoaderHelper.java @@ -71,7 +71,7 @@ public static T instanceFromName(Class targetSuperType, * @return a new instance of classToLoad * * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like - * missing proper constructor, securitymanager errors. + * missing proper constructor errors. */ public static T untypedInstanceFromClass(final Class classToLoad) { try { @@ -140,9 +140,6 @@ private static T callNoArgConstructor(Class classToLoad) Constructor constructor = classToLoad.getConstructor(); return constructor.newInstance(); } - catch (SecurityException e) { - throw log.securityManagerLoadingError( classToLoad, e.getMessage(), e ); - } catch (NoSuchMethodException e) { throw log.noPublicNoArgConstructor( classToLoad ); } @@ -158,9 +155,6 @@ private static T callMapArgConstructor(Class classToLoad, Map singleMapConstructor = classToLoad.getConstructor( Map.class ); return singleMapConstructor.newInstance( constructorParameter ); } - catch (SecurityException e) { - throw log.securityManagerLoadingError( classToLoad, e.getMessage(), e ); - } catch (NoSuchMethodException e) { throw log.noPublicMapArgConstructor( classToLoad ); } diff --git a/engine/src/main/java/org/hibernate/search/engine/environment/thread/impl/EmbeddedThreadProvider.java b/engine/src/main/java/org/hibernate/search/engine/environment/thread/impl/EmbeddedThreadProvider.java index 41bd1995b6a..f158f55b47e 100644 --- a/engine/src/main/java/org/hibernate/search/engine/environment/thread/impl/EmbeddedThreadProvider.java +++ b/engine/src/main/java/org/hibernate/search/engine/environment/thread/impl/EmbeddedThreadProvider.java @@ -4,53 +4,13 @@ */ package org.hibernate.search.engine.environment.thread.impl; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.concurrent.ThreadFactory; -import java.util.function.Supplier; import org.hibernate.search.engine.environment.thread.spi.ThreadProvider; -import org.hibernate.search.engine.logging.impl.Log; -import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis; -import org.hibernate.search.util.common.logging.impl.LoggerFactory; public final class EmbeddedThreadProvider implements ThreadProvider { - private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); - public static final String NAME = "embedded"; - private static final Supplier THREAD_GROUP_PROVIDER; - - static { - Supplier provider = null; - try { - // if the SM is loaded then it means it is still around and we'll try getting the thread group out of it if it is configured: - Class smClass = Thread.currentThread().getContextClassLoader().loadClass( "java.lang.SecurityManager" ); - Method getSecurityManager = System.class.getDeclaredMethod( "getSecurityManager" ); - Method getThreadGroup = smClass.getDeclaredMethod( "getThreadGroup" ); - - provider = () -> { - Object sm; - try { - sm = getSecurityManager.invoke( null ); - if ( sm != null ) { - return (ThreadGroup) getThreadGroup.invoke( sm ); - } - } - catch (InvocationTargetException | IllegalAccessException e) { - // shouldn't really happen, but just in case: - throw log.securityManagerInvocationProblem( e.getMessage(), e ); - } - - return Thread.currentThread().getThreadGroup(); - }; - } - catch (ClassNotFoundException | NoSuchMethodException e) { - provider = () -> Thread.currentThread().getThreadGroup(); - } - THREAD_GROUP_PROVIDER = provider; - } private final String commonThreadNamePrefix; @@ -68,12 +28,11 @@ public String createThreadName(String prefix, int threadNumber) { } @Override - @SuppressForbiddenApis(reason = "It's unclear how we will handle this without the security manager;" - + " we'll see when the security manager actually gets removed from the JDK") public ThreadFactory createThreadFactory(String prefix) { - ThreadGroup group = THREAD_GROUP_PROVIDER.get(); - String namePrefix = createFullThreadNamePrefix( prefix ); - return new SimpleThreadFactory( group, namePrefix ); + return new SimpleThreadFactory( + Thread.currentThread().getThreadGroup(), + createFullThreadNamePrefix( prefix ) + ); } private String createFullThreadNamePrefix(String prefix) { diff --git a/engine/src/main/java/org/hibernate/search/engine/logging/impl/Log.java b/engine/src/main/java/org/hibernate/search/engine/logging/impl/Log.java index 0e66364f5ae..f679a0f91ed 100644 --- a/engine/src/main/java/org/hibernate/search/engine/logging/impl/Log.java +++ b/engine/src/main/java/org/hibernate/search/engine/logging/impl/Log.java @@ -169,10 +169,6 @@ void newCollectedFailure(String process, ) SearchException dslExtensionNoMatch(List attemptedExtensions); - @Message(id = ID_OFFSET + 28, value = "Security manager does not allow access to the constructor of type '%1$s': %2$s") - SearchException securityManagerLoadingError(@FormatWith(ClassFormatter.class) Class classToLoad, - String causeMessage, @Cause Exception cause); - @Message(id = ID_OFFSET + 30, value = "Unable to load class '%1$s': %2$s") ClassLoadingException unableToLoadTheClass(String className, String causeMessage, @Cause Throwable cause); diff --git a/mapper/orm/src/main/java/org/hibernate/search/mapper/orm/model/impl/HibernateOrmBootstrapIntrospector.java b/mapper/orm/src/main/java/org/hibernate/search/mapper/orm/model/impl/HibernateOrmBootstrapIntrospector.java index ef83e7a65c6..38601ddd6be 100644 --- a/mapper/orm/src/main/java/org/hibernate/search/mapper/orm/model/impl/HibernateOrmBootstrapIntrospector.java +++ b/mapper/orm/src/main/java/org/hibernate/search/mapper/orm/model/impl/HibernateOrmBootstrapIntrospector.java @@ -10,7 +10,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Member; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -152,17 +151,10 @@ private HibernateOrmClassRawTypeModel createClassTypeModel(Class type) } private static void setAccessible(Member member) { - try { - // always try to set accessible to true regardless of visibility - // as it's faster even for public fields: - // it bypasses the security model checks at execution time. - ( (AccessibleObject) member ).setAccessible( true ); - } - catch (SecurityException se) { - if ( !Modifier.isPublic( member.getModifiers() ) ) { - throw se; - } - } + // always try to set accessible to true regardless of visibility + // as it's faster even for public fields: + // it bypasses the security model checks at execution time. + ( (AccessibleObject) member ).setAccessible( true ); } /** diff --git a/mapper/pojo-standalone/src/main/java/org/hibernate/search/mapper/pojo/standalone/model/impl/StandalonePojoBootstrapIntrospector.java b/mapper/pojo-standalone/src/main/java/org/hibernate/search/mapper/pojo/standalone/model/impl/StandalonePojoBootstrapIntrospector.java index 4923fbeba6f..22087905e4d 100644 --- a/mapper/pojo-standalone/src/main/java/org/hibernate/search/mapper/pojo/standalone/model/impl/StandalonePojoBootstrapIntrospector.java +++ b/mapper/pojo-standalone/src/main/java/org/hibernate/search/mapper/pojo/standalone/model/impl/StandalonePojoBootstrapIntrospector.java @@ -8,7 +8,6 @@ import java.lang.reflect.AccessibleObject; import java.lang.reflect.Constructor; import java.lang.reflect.Member; -import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Map; @@ -92,16 +91,9 @@ private PojoRawTypeModel createTypeModel(Class clazz) { } private static void setAccessible(Member member) { - try { - // always try to set accessible to true regardless of visibility - // as it's faster even for public fields: - // it bypasses the security model checks at execution time. - ( (AccessibleObject) member ).setAccessible( true ); - } - catch (SecurityException se) { - if ( !Modifier.isPublic( member.getModifiers() ) ) { - throw se; - } - } + // always try to set accessible to true regardless of visibility + // as it's faster even for public fields: + // it bypasses the security model checks at execution time. + ( (AccessibleObject) member ).setAccessible( true ); } }