quarkusio/quarkus · error · IllegalArgumentException

Limiting to 0 values is not supported

Error message

Limiting to 0 values is not supported

What it means

PanacheManagedReactiveQueryImpl.limit(max) rejects max == 0 because Hibernate Reactive range queries cannot express 'return zero rows' via the range(0, max-1) mapping (max-1 would be -1). The limit of 0 is treated as an invalid argument, throwing IllegalArgumentException eagerly when the query is built.

Source

Thrown at extensions/data/hibernate/runtime/src/main/java/io/quarkus/data/hibernate/runtime/hr/PanacheManagedReactiveQueryImpl.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 PanacheManagedReactiveQueryImpl.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 PanacheManagedReactiveQueryImpl.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 PanacheManagedReactiveQueryImpl.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. Guard before calling: skip the query entirely when max <= 0
  2. Clamp the limit to a minimum of 1
  3. Return an empty result list directly instead of executing the query

Example fix

// before
query.limit(requestedSize).list();
// after
if (requestedSize <= 0) { return Uni.createFrom().item(Collections.emptyList()); }
query.limit(requestedSize).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 reactive Panache query to attempt 'fetch nothing' behavior.

Common situations: Dynamically computed page sizes where a zero size slips through (e.g. pageSize = list.size() on an empty list); UI paging components that pass 0 for 'no results'.

Related errors


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