[BUG] IllegalStateException in Twilio.java's static initialization block
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 527
- Forks
- 453
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 6
Description
Describe the bug
This code block in the Twilio class can throw an IllegalStateException:
/*
* Ensures that the ExecutorService is shutdown when the JVM exits.
*/
static {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if (executorService != null) {
executorService.shutdownNow();
}
}
});
}
java.lang.IllegalStateException: Shutdown in progress
at java.base/java.lang.ApplicationShutdownHooks.add(Unknown Source)
at java.base/java.lang.Runtime.addShutdownHook(Unknown Source)
at com.twilio.Twilio.<clinit>(Twilio.java:50)
This happens when the application has already started its shutdown. From Java's Runtime class:
IllegalStateException - If the shutdown sequence has already begun
The fact this is thrown on a static block in library code makes it really difficult to gracefully handle the exception in application code.
Code snippet
Cannot provide application code for legal reasons.
Actual behavior
The library throws the unchecked exception.
Expected behavior
The library should handle the unchecked exception, preventing the issue from propagating.
twilio-java version
11.0.0
Java version
Amazon Corretto Java 24
Logs or error messages
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Twilio.java at the static initialization block that calls Runtime.addShutdownHook, and review how shutdown-in-progress is handled by Java 24. Reproduce or test initialization during JVM shutdown, then verify that the unchecked exception no longer propagates from the library.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100