public static MethodHandles.Lookup getLookupToUse(Class<?> targetClass) throws Exception {
        try {
            if (MODULE_BASED) {
                Object responseModule = CLASS_GET_MODULE_METHOD_HANDLE.invoke(targetClass);

                // The unnamed module is opened unconditionally, have Core read it and use a private proxy lookup to
                // enable all lookup scenarios.
                if (!(boolean) MODULE_IS_NAMED_METHOD_HANDLE.invoke(responseModule)) {
                    MODULE_ADD_READS_METHOD_HANDLE.invokeWithArguments(CORE_MODULE, responseModule);
                    return performSafePrivateLookupIn(targetClass);
                }


                // If the response module is the Core module return the Core private lookup.
                if (responseModule == CORE_MODULE) {
                    return LOOKUP;
                }

                // Next check if the target class module is opened either unconditionally or to Core's module. If so,
                // also use a private proxy lookup to enable all lookup scenarios.
                String packageName = targetClass.getPackage().getName();
                if ((boolean) MODULE_IS_OPEN_UNCONDITIONALLY_METHOD_HANDLE
                    .invokeWithArguments(responseModule, packageName)
                    || (boolean) MODULE_IS_OPEN_TO_OTHER_MODULE_METHOD_HANDLE
                    .invokeWithArguments(responseModule, packageName, CORE_MODULE)) {
                    MODULE_ADD_READS_METHOD_HANDLE.invokeWithArguments(CORE_MODULE, responseModule);
                    return performSafePrivateLookupIn(targetClass);
                }

                // Otherwise, return the public lookup as there are no specialty ways to access the other module.
                return MethodHandles.publicLookup();
            } else {
                return (MethodHandles.Lookup) JDK_INTERNAL_PRIVATE_LOOKUP_IN_CONSTRUCTOR.invoke(targetClass);
            }
        } catch (Throwable throwable) {
            // invoke(Class<?) throws a Throwable as the underlying method being called through reflection can throw
            // anything, but the constructor being called is owned by the Java SDKs which won't throw Throwable. So,
            // only Error needs to be inspected and handled specially, otherwise it can be assumed the Throwable is
            // a type of Exception which can be thrown based on this method having Exception checked.
            if (throwable instanceof Error) {
                throw (Error) throwable;
            } else {
                throw (Exception) throwable;
            }
        }
    }
Gets the {@link MethodHandles.Lookup} to use when performing reflective operations.
<p>
If Java 8 is being used this will always return {@link MethodHandles.Lookup#publicLookup()} as Java 8 doesn't
have module boundaries that will prevent reflective access to the {@code targetClass}.
<p>
If Java 9 or above is being used this will return a {@link MethodHandles.Lookup} based on whether the module
containing the {@code targetClass} exports the package containing the class. Otherwise, the
{@link MethodHandles.Lookup} associated to {@code com.azure.core} will attempt to read the module containing
{@code targetClass}.

@param targetClass The {@link Class} that will need to be reflectively accessed.
@return The {@link MethodHandles.Lookup} that will allow {@code com.azure.core} to access the {@code targetClass}
reflectively.
@throws Exception If the underlying reflective calls throw an exception.
chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/util/AzureReflectionUtils.java