{"record":{"id":"2d05fdcf086ebf11","repo":"apache/iceberg","slug":"noop-timer-has-no-unit","errorCode":null,"errorMessage":"NOOP timer has no unit","messagePattern":"NOOP timer has no unit","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/metrics/Timer.java","lineNumber":150,"sourceCode":"      new Timer() {\n        @Override\n        public Timed start() {\n          return Timed.NOOP;\n        }\n\n        @Override\n        public long count() {\n          throw new UnsupportedOperationException(\"NOOP timer has no count\");\n        }\n\n        @Override\n        public Duration totalDuration() {\n          throw new UnsupportedOperationException(\"NOOP timer has no duration\");\n        }\n\n        @Override\n        public TimeUnit unit() {\n          throw new UnsupportedOperationException(\"NOOP timer has no unit\");\n        }\n\n        @Override\n        public void record(long amount, TimeUnit unit) {}\n\n        @Override\n        public void time(Runnable runnable) {}\n\n        @Override\n        public <T> T timeCallable(Callable<T> callable) throws Exception {\n          return callable.call();\n        }\n\n        @Override\n        public <T> T time(Supplier<T> supplier) {\n          return supplier.get();\n        }\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/metrics/Timer.java#L132-L168","documentation":"The NOOP Timer has no configured reporting time unit because it never stores measurements. unit() throws UnsupportedOperationException to signal that this timer is a no-op sink and cannot describe its units. Only real timer implementations carry a TimeUnit.","triggerScenarios":"Calling Timer.NOOP.unit(), typically when serializing or reporting metrics and the code asks each timer for its unit regardless of implementation.","commonSituations":"Metric report/serialization code (e.g. producing commit reports) that queries unit() on every timer in a metrics structure while metrics are disabled; generic metric aggregation utilities.","solutions":["Use a concrete Timer implementation with a defined unit instead of Timer.NOOP when unit information is required.","Branch on the NOOP instance and supply a default TimeUnit (e.g. TimeUnit.NANOSECONDS) for reporting purposes.","Filter out NOOP timers before iterating timers in report-building code."],"exampleFix":"// before\nTimeUnit unit = timer.unit();\n// after\nTimeUnit unit = (timer == Timer.NOOP) ? TimeUnit.NANOSECONDS : timer.unit();","handlingStrategy":"type-guard","validationCode":"boolean hasUnit = timer != Timer.NOOP;","typeGuard":"if (timer == Timer.NOOP) { return TimeUnit.NANOSECONDS; } return timer.unit();","tryCatchPattern":"try { return timer.unit(); } catch (UnsupportedOperationException e) { return TimeUnit.NANOSECONDS; }","preventionTips":["Default the unit at the reporting layer instead of querying NOOP timers","Filter NOOP instances before serializing metrics","Document that NOOP metrics are write-only"],"tags":["java","metrics","unsupported-operation","noop"],"backgroundTag":"unsupported-operation","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"}