{"record":{"id":"5eee059e736ee42c","repo":"apache/iceberg","slug":"count-is-not-supported","errorCode":null,"errorMessage":"Count is not supported.","messagePattern":"Count is not supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java","lineNumber":92,"sourceCode":"\n    /**\n     * Reporting count is optional if the counter is reporting externally.\n     *\n     * @return current count if available\n     * @deprecated Use {@link Counter#value()}\n     */\n    @Deprecated\n    default Optional<T> count() {\n      return Optional.empty();\n    }\n\n    /**\n     * Reports the current count.\n     *\n     * @return The current count\n     */\n    default T value() {\n      throw new UnsupportedOperationException(\"Count is not supported.\");\n    }\n\n    /**\n     * The unit of the counter.\n     *\n     * @return The unit of the counter.\n     */\n    default Unit unit() {\n      return Unit.UNDEFINED;\n    }\n  }\n\n  /**\n   * Get a named counter of a specific type. Metric implementations may impose restrictions on what\n   * types are supported for specific counters.\n   *\n   * @param name name of the metric\n   * @param type numeric type of the counter value","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java#L74-L110","documentation":"Counter.value() is a default method on the MetricsContext.Counter interface that throws UnsupportedOperationException('Count is not supported.') — implementations are expected to override it. A context that does not support counters (or a custom Counter implementation that skips it) leaves this stub in place, so reading the count fails.","triggerScenarios":"Calling value() on a Counter returned by a MetricsContext that did not override value(), e.g. a custom MetricsContext extending the interface without implementing counters, or the deprecated counter() default stubs on the interface.","commonSituations":"Custom MetricsContext implementations missing value() overrides; code reading counter values from contexts that were never meant to record (unsupported default methods); upgrade paths where a new interface method wasn't implemented.","solutions":["Override value() in your Counter implementation to return the real count","Use DefaultMetricsContext/DefaultCounter which implement value()","Don't read value() from counters obtained via unsupported contexts; use toString or count() where appropriate","Check the MetricsContext implementation actually records before consuming values"],"exampleFix":"// before\nclass MyCounter implements Counter<Long> { /* value() not overridden */ }\n// after\nclass MyCounter implements Counter<Long> {\n  @Override\n  public Long value() { return count.get(); }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { counter.value(); } catch (UnsupportedOperationException e) { skip; }","preventionTips":["Override value() in custom counters","Use DefaultMetricsContext"],"tags":["java","metrics","unsupported-operation"],"backgroundTag":"method-not-implemented","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"}