{"record":{"id":"8043d332fef87e07","repo":"apache/iceberg","slug":"unable-to-load-metrics-class-falling-back-t-8043d3","errorCode":null,"errorMessage":"Unable to load metrics class: '{}', falling back to null metrics","messagePattern":"Unable to load metrics class: '(.+?)', falling back to null metrics","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java","lineNumber":532,"sourceCode":"      }\n    }\n\n    initMetrics(properties);\n  }\n\n  @SuppressWarnings(\"CatchBlockLogException\")\n  private void initMetrics(Map<String, String> props) {\n    // Report Hadoop metrics if Hadoop is available\n    try {\n      DynConstructors.Ctor<MetricsContext> ctor =\n          DynConstructors.builder(MetricsContext.class)\n              .hiddenImpl(DEFAULT_METRICS_IMPL, String.class)\n              .buildChecked();\n      MetricsContext context = ctor.newInstance(ROOT_PREFIX);\n      context.initialize(props);\n      this.metrics = context;\n    } catch (NoClassDefFoundError | NoSuchMethodException | ClassCastException e) {\n      LOG.warn(\n          \"Unable to load metrics class: '{}', falling back to null metrics\", DEFAULT_METRICS_IMPL);\n    }\n  }\n\n  @Override\n  public void close() {\n    // handles concurrent calls to close()\n    if (isResourceClosed.compareAndSet(false, true)) {\n      if (clientByPrefix != null) {\n        clientByPrefix.values().forEach(PrefixedS3Client::close);\n        this.clientByPrefix = null;\n      }\n      if (refreshFuture != null) {\n        refreshFuture.cancel(true);\n        refreshFuture = null;\n      }\n    }\n  }","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java#L514-L550","documentation":"S3FileIO.initMetrics() tries to instantiate the configured metrics implementation class (default MetricsContext) reflectively. If the class is missing, has no compatible constructor, or doesn't implement MetricsContext, it logs this warning and falls back to null metrics — FileIO keeps working but metrics collection is disabled.","triggerScenarios":"initialize() called on a classpath missing the metrics dependency (e.g. iceberg-aws-bundle trimmed, micrometer/config libs absent), or a custom metrics class name configured that isn't a MetricsContext or lacks a (String) constructor.","commonSituations":"Shaded/thin deployment jars missing optional metrics dependencies; upgrading Iceberg where the metrics impl class moved; typo in metrics impl configuration.","solutions":["Add the metrics-related dependencies to the classpath (or use the full iceberg-aws-bundle)","Set the metrics impl property to a class that exists and implements MetricsContext","Accept the fallback if metrics are not needed — this warning is harmless otherwise","Fix NoSuchMethodException cases by ensuring the impl has a public constructor taking a String scope name"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"try {\n  Class.forName(\"org.apache.iceberg.metrics.LoggingMetricsContext\");\n} catch (ClassNotFoundException e) {\n  // metrics dependency missing; add it or accept null metrics\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship the full iceberg-aws-bundle or explicitly add metrics dependencies","Validate configured metrics impl class implements MetricsContext with a (String) constructor","Treat this warning as informational unless metrics are operationally required"],"tags":["reflection","classpath","metrics","fallback"],"backgroundTag":"class-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}