{"record":{"id":"5c0718c2653658f3","repo":"google/guava","slug":"schedulewithfixeddelay-is-not-supported","errorCode":null,"errorMessage":"scheduleWithFixedDelay is not supported.","messagePattern":"scheduleWithFixedDelay 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":186,"sourceCode":"    }\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":168,"sourceCodeEnd":189,"githubUrl":"https://github.com/google/guava/blob/94f39958baf7ad51ddf9c70e406ed6b188194daa/android/guava-testlib/src/com/google/common/util/concurrent/testing/SameThreadScheduledExecutorService.java#L168-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; scheduleWithFixedDelay throws UnsupportedOperationException by design.","triggerScenarios":"Code under test calls executor.scheduleWithFixedDelay(command, initialDelay, delay, unit) on an instance of SameThreadScheduledExecutorService provided by a test.","commonSituations":"Injecting this fake executor into code that performs periodic scheduling with a fixed delay between completions (e.g. backoff retries, heartbeat loops); tests migrated from a real ScheduledExecutorService without noticing the fake omits fixed-delay scheduling.","solutions":["Switch the test to a real ScheduledThreadPoolExecutor (or a more complete fake) for code paths that use scheduleWithFixedDelay.","Refactor the code under test to depend on a Scheduler abstraction so the periodic path can be stubbed without this executor.","Split the test so periodic scheduling is exercised against a real executor while synchronous parts use the fake.","Replace fixed-delay scheduling with chained one-shot schedule(...) calls the fake does support."],"exampleFix":"// before\nSameThreadScheduledExecutorService ex = new SameThreadScheduledExecutorService();\nex.scheduleWithFixedDelay(task, 0, 1, SECONDS); // UnsupportedOperationException\n\n// after\nScheduledExecutorService ex = Executors.newScheduledThreadPool(1);\nex.scheduleWithFixedDelay(task, 0, 1, SECONDS);","handlingStrategy":"validation","validationCode":"boolean usesFixedDelay = schedulingType == SchedulingType.WITH_FIXED_DELAY;\nScheduledExecutorService ex = usesFixedDelay\n    ? Executors.newScheduledThreadPool(1)\n    : new SameThreadScheduledExecutorService();","typeGuard":"boolean supportsFixedDelay(ScheduledExecutorService ex) {\n  return !(ex instanceof SameThreadScheduledExecutorService);\n}","tryCatchPattern":"// UnsupportedOperationException signals wrong test double; switch executors,\n// do not swallow it.","preventionTips":["Do not inject SameThreadScheduledExecutorService into code that calls scheduleWithFixedDelay.","Use a real ScheduledThreadPoolExecutor for fixed-delay paths.","Abstract scheduling behind an interface so tests can stub it directly.","Confirm which scheduling 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-14T05:17:29.042Z"}