Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArithmeticException: long overflow on @Scheduled(fixedDelay = Long.MAX_VALUE, timeUnit = TimeUnit.MINUTES) #31210

Closed
marceloverdijk opened this issue Sep 13, 2023 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@marceloverdijk
Copy link

This is similar as #30754

Note I can confirm the original issue is solved in Spring 6.0.11 as this works:

@Scheduled(initialDelay = 5, fixedDelay = Long.MAX_VALUE)

but using:

@Scheduled(initialDelay = 5, fixedDelay = Long.MAX_VALUE, timeUnit = TimeUnit.MINUTES)

still gives the ArithmeticException:

Caused by: java.lang.ArithmeticException: long overflow
	at java.base/java.lang.Math.multiplyExact(Math.java:1004) ~[na:na]
	at java.base/java.time.Duration.plus(Duration.java:729) ~[na:na]
	at java.base/java.time.Duration.of(Duration.java:312) ~[na:na]
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.toDuration(ScheduledAnnotationBeanPostProcessor.java:535) ~[spring-context-6.0.11.jar:6.0.11]
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:452) ~[spring-context-6.0.11.jar:6.0.11]
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$1(ScheduledAnnotationBeanPostProcessor.java:377) ~[spring-context-6.0.11.jar:6.0.11]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$2(ScheduledAnnotationBeanPostProcessor.java:377) ~[spring-context-6.0.11.jar:6.0.11]
	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721) ~[na:na]
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:376) ~[spring-context-6.0.11.jar:6.0.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434) ~[spring-beans-6.0.11.jar:6.0.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773) ~[spring-beans-6.0.11.jar:6.0.11]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[spring-beans-6.0.11.jar:6.0.11]
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 13, 2023
@jhoeller
Copy link
Contributor

That's an earlier arithmetic exception in the Duration.of factory method, so it is not directly related to our nanoseconds revision. I suppose we could catch the exception and throw a better-worded IllegalArgumentException there.

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 13, 2023
@jhoeller jhoeller self-assigned this Sep 13, 2023
@jhoeller jhoeller added this to the 6.0.12 milestone Sep 13, 2023
@marceloverdijk
Copy link
Author

Indeed, similar as Duration.of(Long.MAX_VALUE, ChronoUnit.MINUTES) gives the same ArithmeticException.

Maybe it would be more interesting to have the possibility to run @Scheduled only once (with an initial delay)?

@jhoeller
Copy link
Contributor

That's a good point. Rather than insisting on cron/fixedDelay/fixedRate to be specified, we could accept just an initial delay for a one-time task, delegating to TaskScheduler.schedule(Runnable task, Instant startTime). Please create a separate ticket for that, I'll try to roll this into 6.1 then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants