Skip to content

Commit 1781511

Browse files
authored
Prevent crash from ZipFile GC cleanup I/O errors (#957)
When a ZipFile is garbage collected and its underlying file descriptor is no longer valid, the FinalizerDaemon throws UncheckedIOException wrapping an EIO error. This is a non-critical platform issue — the object is already unreachable and the OS reclaims the fd on process exit. Detect this specific pattern via CleanableResource/PhantomCleanable in the stack trace, report to Sentry, and return without killing the process.
1 parent 3077688 commit 1781511

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,24 @@ class IDEApplication : BaseApplication() {
184184
thread: Thread,
185185
exception: Throwable,
186186
) {
187+
if (isNonFatalGcCleanupFailure(exception)) {
188+
logger.warn("Non-fatal: ZipFile GC cleanup failed with I/O error", exception)
189+
return
190+
}
191+
187192
if (isUserUnlocked) {
188-
// we can access credential protected storage, delegate the job to
189-
// to advanced crash handler
190193
CredentialProtectedApplicationLoader.handleUncaughtException(thread, exception)
191194
return
192195
}
193196

194-
// we can only access device-protected storage, and are not allowed
195-
// to show crash handler screen
196-
// delegate the job to the basic crash handler
197197
DeviceProtectedApplicationLoader.handleUncaughtException(thread, exception)
198198
}
199+
200+
private fun isNonFatalGcCleanupFailure(exception: Throwable): Boolean {
201+
if (exception !is java.io.UncheckedIOException) return false
202+
return exception.stackTrace.any {
203+
it.className.contains("CleanableResource") ||
204+
it.className.contains("PhantomCleanable")
205+
}
206+
}
199207
}

subprojects/javac-services/src/main/java/com/itsaky/androidide/javac/services/fs/CachedJarFileSystem.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CachedJarFileSystem(
4747
// This is called manually by the Java LSP
4848
}
4949

50+
@Throws(IOException::class)
5051
fun doClose() {
5152
try {
5253
super.close()

0 commit comments

Comments
 (0)