quarkusio/quarkus · error · IllegalArgumentException

Limiting to 0 values is not supported

Error message

Limiting to 0 values is not supported

What it means

PanacheStatelessReactiveQueryImpl.limit(max) throws IllegalArgumentException when max == 0, because the underlying range(0, max-1) delegation cannot represent an empty limit. Zero is therefore an invalid argument at query construction time.

Source

Thrown at extensions/data/hibernate/runtime/src/main/java/io/quarkus/data/hibernate/runtime/hr/PanacheStatelessReactiveQueryImpl.java:42

    final Limits<ReactiveDataQuery<Entity>> limitingDelegate = new Limits<ReactiveDataQuery<Entity>>() {
        @Override
        public Limit limit() {
            io.quarkus.panache.common.Range range = delegate.range();
            // convert 0-based range to 1-based Jakarta Data Limit
            return Limit.range(range.getStartIndex() + 1, range.getLastIndex() + 1);
        }

        @Override
        public ReactiveDataQuery<Entity> limit(Limit limit) {
            // startAt is 1-based in Jakarta Data, convert to 0-based; end is inclusive, hence -1 on size
            delegate.range((int) (limit.startAt() - 1), (int) (limit.startAt() + limit.maxResults() - 2));
            return PanacheStatelessReactiveQueryImpl.this;
        }

        @Override
        public ReactiveDataQuery<Entity> limit(int max) {
            if (max == 0) {
                throw new IllegalArgumentException("Limiting to 0 values is not supported");
            }
            // end is inclusive, hence -1 on size
            delegate.range(0, max - 1);
            return PanacheStatelessReactiveQueryImpl.this;
        }

        @Override
        public ReactiveDataQuery<Entity> limit(long start, int max) {
            // end is inclusive, hence -1 on size
            delegate.range((int) start, (int) (start + max - 1));
            return PanacheStatelessReactiveQueryImpl.this;
        }

        @Override
        public ReactiveDataQuery<Entity> limitFrom(long start) {
            // end is inclusive, hence -1 on size
            // default page size of Jakarta Data is 10 (see PageRequest)
            delegate.range((int) start, (int) (start + 10 - 1));

View on GitHub (pinned to e1c734241f)

Solutions

  1. Short-circuit and return an empty list when the requested limit is 0
  2. Enforce a minimum limit of 1 (clamp)
  3. Validate page-size configuration so 0 never reaches the query

Example fix

// before
statelessQuery.limit(cfg.pageSize).list();
// after
int size = Math.max(1, cfg.pageSize);
statelessQuery.limit(size).list();
Defensive patterns

Strategy: validation

Validate before calling

if (max <= 0) { return Uni.createFrom().item(Collections.emptyList()); }

Type guard

int requirePositiveLimit(int max) { if (max <= 0) throw new IllegalArgumentException("limit must be >= 1, got " + max); return max; }

Try / catch

try { q.limit(max); } catch (IllegalArgumentException e) { return Uni.createFrom().item(List.of()); }

Prevention

When it happens

Trigger: Calling limit(0) on a stateless reactive Panache query.

Common situations: Zero page size computed from empty collections or configuration defaults; code reusing limit(0) as a count-only trick, which is not supported.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/eaed8b665b3ddd88. Report an issue: GitHub.