{"record":{"id":"35fcef64dd17e215","repo":"google/guava","slug":"scheduleatfixedrate-is-not-supported","errorCode":null,"errorMessage":"scheduleAtFixedRate is not supported.","messagePattern":"scheduleAtFixedRate is not supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java","lineNumber":180,"sourceCode":"    }\n\n    @Override\n    public long getDelay(TimeUnit unit) {\n      Preconditions.checkNotNull(unit, \"unit must not be null!\");\n      return 0;\n    }\n\n    @Override\n    public int compareTo(Delayed other) {\n      Preconditions.checkNotNull(other, \"other must not be null!\");\n      return 0;\n    }\n  }\n\n  @Override\n  public ListenableScheduledFuture<?> scheduleAtFixedRate(\n      Runnable command, long initialDelay, long period, TimeUnit unit) {\n    throw new UnsupportedOperationException(\"scheduleAtFixedRate is not supported.\");\n  }\n\n  @Override\n  public ListenableScheduledFuture<?> scheduleWithFixedDelay(\n      Runnable command, long initialDelay, long delay, TimeUnit unit) {\n    throw new UnsupportedOperationException(\"scheduleWithFixedDelay is not supported.\");\n  }\n}\n","sourceCodeStart":162,"sourceCodeEnd":189,"githubUrl":"https://github.com/google/guava/blob/94f39958baf7ad51ddf9c70e406ed6b188194daa/android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java#L162-L189","documentation":"SameThreadScheduledExecutorService is a deliberately minimal synchronous test double that runs submitted tasks on the caller thread. It implements one-shot scheduling but intentionally does not support periodic scheduling; scheduleAtFixedRate throws UnsupportedOperationException by design.","triggerScenarios":"Code under test calls executor.scheduleAtFixedRate(command, initialDelay, period, unit) on an instance of SameThreadScheduledExecutorService provided by a test.","commonSituations":"Injecting this fake executor into code that performs periodic scheduling (polling, retries, cleanup loops); migrating tests from a real ScheduledExecutorService without realizing the fake omits fixed-rate scheduling.","solutions":["Switch the test to a real ScheduledThreadPoolExecutor (or a more complete fake) for code paths that use scheduleAtFixedRate.","Refactor the code under test to depend on an abstraction (e.g. a Scheduler interface) so periodic scheduling can be stubbed without going through this executor.","Split the test so the periodic-scheduling path is exercised against a real executor while only the synchronous parts use this fake.","Avoid scheduling at a fixed rate; use repeated one-shot schedule(...) calls the fake does support."],"exampleFix":"// before\nSameThreadScheduledExecutorService ex = new SameThreadScheduledExecutorService();\nex.scheduleAtFixedRate(task, 0, 1, SECONDS); // UnsupportedOperationException\n\n// after\nScheduledExecutorService ex = Executors.newScheduledThreadPool(1);\nex.scheduleAtFixedRate(task, 0, 1, SECONDS);","handlingStrategy":"validation","validationCode":"// Only inject the fake when the code path does not use fixed-rate scheduling.\nboolean usesFixedRate = schedulingType == SchedulingType.AT_FIXED_RATE;\nScheduledExecutorService ex = usesFixedRate\n    ? Executors.newScheduledThreadPool(1)\n    : new SameThreadScheduledExecutorService();","typeGuard":"// Detect capability before calling, since the fake lacks it.\nboolean supportsFixedRate(ScheduledExecutorService ex) {\n  return !(ex instanceof SameThreadScheduledExecutorService);\n}","tryCatchPattern":"// UnsupportedOperationException is a programmer error in test setup; do not\n// catch and continue. Switch executors instead.","preventionTips":["Do not inject SameThreadScheduledExecutorService into code that calls scheduleAtFixedRate.","Use a real ScheduledThreadPoolExecutor for periodic-scheduling paths.","Abstract scheduling behind an interface so tests can stub it directly.","Map out which ScheduledExecutorService operations the fake supports before wiring it."],"tags":["guava","testing","concurrency","executor","unsupported-operation","scheduled"],"backgroundTag":null,"analyzedSha":"94f39958baf7ad51ddf9c70e406ed6b188194daa","analyzedAt":"2026-08-13T22:50:30.265Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}