binarywang/WxJava · error · IllegalArgumentException
Parameter 'leaseMilliseconds' must grate then 0: {}
Error message
Parameter 'leaseMilliseconds' must grate then 0: {} What it means
Thrown by the RedisTemplateSimpleDistributedLock constructor when leaseMilliseconds <= 0. The lease is used as the Redis key TTL (expire), so a non-positive value would create a lock that never expires or fails to set; the constructor rejects it up front with IllegalArgumentException. (Note the message typo 'grate' meaning 'greater'.)
Source
Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/RedisTemplateSimpleDistributedLock.java:36
*/
public class RedisTemplateSimpleDistributedLock implements Lock {
@Getter
private final StringRedisTemplate redisTemplate;
@Getter
private final String key;
@Getter
private final int leaseMilliseconds;
private final ThreadLocal<String> valueThreadLocal = new ThreadLocal<>();
public RedisTemplateSimpleDistributedLock( StringRedisTemplate redisTemplate, int leaseMilliseconds) {
this(redisTemplate, "lock:" + UUID.randomUUID().toString(), leaseMilliseconds);
}
public RedisTemplateSimpleDistributedLock( StringRedisTemplate redisTemplate, String key, int leaseMilliseconds) {
if (leaseMilliseconds <= 0) {
throw new IllegalArgumentException("Parameter 'leaseMilliseconds' must grate then 0: " + leaseMilliseconds);
}
this.redisTemplate = redisTemplate;
this.key = key;
this.leaseMilliseconds = leaseMilliseconds;
}
@Override
public void lock() {
boolean interrupted = false;
while (!tryLock()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
interrupted = true;
}
}
if (interrupted) {
Thread.currentThread().interrupt();View on GitHub (pinned to 1c43293a3c)
Solutions
- Set leaseMilliseconds to a positive value greater than the expected hold time (e.g. 30000).
- Validate the configured value at application startup and fail fast with a clear message.
- Make sure units match (milliseconds here, not seconds).
Example fix
// before new RedisTemplateSimpleDistributedLock(template, 0); // after new RedisTemplateSimpleDistributedLock(template, 30000);
Defensive patterns
Strategy: validation
Validate before calling
int lease = configuredLeaseMillis; // from config
if (lease <= 0) throw new IllegalStateException("leaseMilliseconds must be > 0");
new RedisTemplateSimpleDistributedLock(template, lease); Type guard
static boolean validLease(int ms) { return ms > 0; } Try / catch
null
Prevention
- Provide an explicit positive leaseMillis in configuration.
- Validate the value at startup, not just at construction.
- Remember the unit is milliseconds, not seconds.
When it happens
Trigger: Constructing the lock with a zero or negative leaseMilliseconds, often from misconfigured properties, a default of 0, or an arithmetic expression that underflows.
Common situations: Spring @Value property missing so it defaults to 0; passing a configured millis that was divided/rounded to 0; copy-paste of a seconds value into a millis parameter.
Related errors
- acquire timeouted
- lock failed
- unsupported method
- uri参数中不允许有suite_access_token: {}
- uri参数中不允许有access_token:
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/7f6e051efb7cc31f.
Report an issue: GitHub.