From 0caaf30cab67090e093039222f084f128701baf9 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 8 Mar 2023 09:43:02 +0100 Subject: [PATCH] Throw exception on asking for configuration that is not available. --- .../java/co/elastic/apm/agent/impl/ElasticApmTracer.java | 9 ++++++--- .../main/java/co/elastic/apm/agent/impl/NoopTracer.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java index 3f9a09a6076..8273b1f8d1e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java @@ -378,11 +378,14 @@ public ConfigurationRegistry getConfigurationRegistry() { @Override @SuppressWarnings({"unchecked", "rawtypes"}) public T getConfig(Class configProvider) { + T configuration = null; if (ConfigurationOptionProvider.class.isAssignableFrom(configProvider)) { - return (T) configurationRegistry.getConfig((Class) configProvider); - } else { - return null; + configuration = (T) configurationRegistry.getConfig((Class) configProvider); + } + if (configuration == null) { + throw new IllegalStateException("no configuration available for " + configProvider.getName()); } + return configuration; } public void endTransaction(Transaction transaction) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java index 76dc5f7db76..aff87d21c47 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java @@ -169,7 +169,7 @@ public T require(Class type) { @Override public T getConfig(Class configuration) { - return null; + throw new IllegalStateException(); } @Override