{"record":{"id":"dcddf2551725b040","repo":"quarkusio/quarkus","slug":"the-timestamp-must-be-positive","errorCode":null,"errorMessage":"The timestamp must be positive","messagePattern":"The timestamp must be positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/timeseries/MRangeArgs.java","lineNumber":61,"sourceCode":"    public MRangeArgs latest() {\n        this.latest = true;\n        return this;\n    }\n\n    /**\n     * Filters samples by a list of specific timestamps.\n     * A sample passes the filter if its exact timestamp is specified and falls within [fromTimestamp, toTimestamp].\n     *\n     * @param timestamps the timestamps\n     * @return the current {@code MRangeArgs}\n     */\n    public MRangeArgs filterByTimestamp(long... timestamps) {\n        if (filterByTimestamps == null) {\n            filterByTimestamps = new ArrayList<>(timestamps.length);\n        }\n        for (long timestamp : timestamps) {\n            if (timestamp < 0) {\n                throw new IllegalArgumentException(\"The timestamp must be positive\");\n            }\n            filterByTimestamps.add(timestamp);\n        }\n        return this;\n    }\n\n    /**\n     * Filters samples by minimum and maximum values.\n     *\n     * @param min the min value of the sample\n     * @param max the max value of the sample\n     * @return the current {@code MRangeArgs}\n     */\n    public MRangeArgs filterByValue(double min, double max) {\n        this.filterByValue = true;\n        this.min = min;\n        this.max = max;\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/timeseries/MRangeArgs.java#L43-L79","documentation":"MRangeArgs.filterByTimestamp(long...) filters TS_MRANGE samples to the given timestamps. RedisTimeSeries timestamps are non-negative epoch millis, so any negative value is rejected with IllegalArgumentException before the command is sent. Zero is allowed; only negative values fail.","triggerScenarios":"Calling filterByTimestamp with any negative long — e.g. filterByTimestamp(-1), or computed values like System.currentTimeMillis() - duration where duration exceeds the epoch time, or sentinel values like -1 used to mean 'unset'.","commonSituations":"Using -1 as a 'no timestamp' sentinel; subtracting a too-large offset from currentTimeMillis(); receiving negative timestamps from upstream data or misparsed dates.","solutions":["Filter out negative values before calling: long[] valid = Arrays.stream(ts).filter(t -> t >= 0).toArray()","Fix the computation producing the negative timestamp (e.g. clamp to 0)","Replace -1 sentinels with a proper Optional/absence representation instead of passing them to filterByTimestamp"],"exampleFix":"// before\nargs.filterByTimestamp(sinceMillis - lookback); // can go negative\n// after\nlong from = Math.max(0, sinceMillis - lookback);\nargs.filterByTimestamp(from);","handlingStrategy":"validation","validationCode":"long[] safe = Arrays.stream(timestamps)\n    .peek(t -> { if (t < 0) throw new IllegalArgumentException(\"negative timestamp: \" + t); })\n    .toArray();\nargs.filterByTimestamp(safe);","typeGuard":"boolean allTimestampsValid(long... ts) {\n    return ts == null || Arrays.stream(ts).allMatch(t -> t >= 0);\n}","tryCatchPattern":"try {\n    args.filterByTimestamp(timestamps);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Skipping invalid timestamp filter: \" + e.getMessage());\n}","preventionTips":["Never use -1 as a timestamp sentinel; use Optional or omit the filter","Clamp computed epoch values with Math.max(0, value)","Sanitize upstream timestamp data before passing to filterByTimestamp"],"tags":["java","redis","redis-timeseries","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}