From 289c8c40ac29df6fc39481448d8c591c914b2e71 Mon Sep 17 00:00:00 2001 From: Holly Cummins Date: Wed, 18 Dec 2024 21:49:16 +0000 Subject: [PATCH] Revert formatting churn --- .../RunningQuarkusApplicationImpl.java | 63 ++++++++----------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/RunningQuarkusApplicationImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/RunningQuarkusApplicationImpl.java index d27f043652aa2..7f18f7f9bd44b 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/RunningQuarkusApplicationImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/RunningQuarkusApplicationImpl.java @@ -42,39 +42,30 @@ public void close() throws Exception { @Override public Optional getConfigValue(String key, Class type) { - if (false && new Exception().getStackTrace().length > 100) { - // TODO expensive, awkward - System.out.println("HOLLY averting infinite loop " + key); - new Exception().printStackTrace(); - return Optional.empty(); - } else { - ClassLoader old = Thread.currentThread() - .getContextClassLoader(); - try { - // TODO this infinite loops, check that assumption - // we are assuming here that the the classloader has been initialised with some kind of different provider that does not infinite loop. - Thread.currentThread() - .setContextClassLoader(classLoader); - if (classLoader == ConfigProvider.class.getClassLoader()) { - return ConfigProvider.getConfig(classLoader) - .getOptionalValue(key, type); - } else { - //the config is in an isolated CL - //we need to extract it via reflection - //this is pretty yuck, but I don't really see a solution - Class configProviderClass = classLoader.loadClass(ConfigProvider.class.getName()); - Method getConfig = configProviderClass.getMethod("getConfig", ClassLoader.class); - Object config = getConfig.invoke(null, classLoader); - return (Optional) getConfig.getReturnType() - .getMethod("getOptionalValue", String.class, Class.class) - .invoke(config, key, type); - } - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - Thread.currentThread() - .setContextClassLoader(old); + ClassLoader old = Thread.currentThread() + .getContextClassLoader(); + try { + // we are assuming here that the the classloader has been initialised with some kind of different provider that does not infinite loop. + Thread.currentThread() + .setContextClassLoader(classLoader); + if (classLoader == ConfigProvider.class.getClassLoader()) { + return ConfigProvider.getConfig(classLoader) + .getOptionalValue(key, type); + } else { + //the config is in an isolated CL + //we need to extract it via reflection + //this is pretty yuck, but I don't really see a solution + Class configProviderClass = classLoader.loadClass(ConfigProvider.class.getName()); + Method getConfig = configProviderClass.getMethod("getConfig", ClassLoader.class); + Object config = getConfig.invoke(null, classLoader); + return (Optional) getConfig.getReturnType() + .getMethod("getOptionalValue", String.class, Class.class) + .invoke(config, key, type); } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + Thread.currentThread().setContextClassLoader(old); } } @@ -113,14 +104,10 @@ public Object instance(Class clazz, Annotation... qualifiers) { } Class cdi = classLoader.loadClass("jakarta.enterprise.inject.spi.CDI"); - Object instance = cdi.getMethod("current") - .invoke(null); + Object instance = cdi.getMethod("current").invoke(null); Method selectMethod = cdi.getMethod("select", Class.class, Annotation[].class); Object cdiInstance = selectMethod.invoke(instance, actualClass, qualifiers); - return selectMethod.getReturnType() - .getMethod("get") - .invoke(cdiInstance); - + return selectMethod.getReturnType().getMethod("get").invoke(cdiInstance); } catch (Exception e) { throw new RuntimeException(e); }