Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ class IDEApplication :
return
}

if (isFinalizerWatchdogTimeout(thread, exception)) {
logger.warn("Non-fatal: FinalizerWatchdogDaemon timeout (suppressed crash)", exception)
Sentry.captureException(exception)
return
}

if (isUserUnlocked) {
CredentialProtectedApplicationLoader.handleUncaughtException(thread, exception)
return
Expand All @@ -226,4 +232,10 @@ class IDEApplication :
it.className.contains("PhantomCleanable")
}
}

private fun isFinalizerWatchdogTimeout(thread: Thread, exception: Throwable): Boolean {
if (exception !is java.util.concurrent.TimeoutException) return false
return thread.name.contains("FinalizerWatchdogDaemon") ||
exception.stackTrace.any { it.className.contains("Daemons\$FinalizerWatchdogDaemon") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1089,13 +1089,11 @@ private static void closeChannelQuietly(SeekableByteChannel channel) {

@SuppressWarnings("deprecation")
protected void finalize() throws IOException {
try {
close();
} catch (Throwable ignored) {
// On devices with flaky storage, close() can throw UncheckedIOException
// wrapping EIO. Swallow all errors during finalization to prevent
// killing the FinalizerDaemon thread.
}
// No-op: do NOT perform I/O during finalization.
// On slow storage, close() can exceed the 10-second FinalizerWatchdogDaemon
// timeout, causing a fatal TimeoutException crash (Sentry APPDEVFORALL-E8).
// All ZipFileSystems should be closed deterministically via close()/doClose().
// The OS reclaims file descriptors at process exit regardless.
}

// Reads len bytes of data from the specified offset into buf.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,52 +97,51 @@ object TooltipManager {
try {
val db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READONLY)

var cursor = db.rawQuery(QUERY_LAST_CHANGE, arrayOf())
cursor.moveToFirst()

lastChange = "${cursor.getString(0)} ${cursor.getString(1)}"

Log.d(TAG, "last change is '${lastChange}'.")
db.use { database ->
database.rawQuery(QUERY_LAST_CHANGE, arrayOf()).use { c ->
c.moveToFirst()
lastChange = "${c.getString(0)} ${c.getString(1)}"
}

cursor = db.rawQuery(QUERY_TOOLTIP, arrayOf(tag, category))
Log.d(TAG, "last change is '${lastChange}'.")

when (cursor.count) {
0 -> throw NoTooltipFoundException(category, tag)
1 -> { /* Expected case, continue processing */
}
database.rawQuery(QUERY_TOOLTIP, arrayOf(tag, category)).use { c ->
when (c.count) {
0 -> throw NoTooltipFoundException(category, tag)
1 -> { /* Expected case, continue processing */
}

else -> throw DatabaseCorruptionException(
"Multiple tooltips found for category='$category', tag='$tag' (found ${cursor.count} rows). " +
"Each category/tag combination should be unique."
)
}
else -> throw DatabaseCorruptionException(
"Multiple tooltips found for category='$category', tag='$tag' (found ${c.count} rows). " +
"Each category/tag combination should be unique."
)
}

cursor.moveToFirst()
c.moveToFirst()

rowId = cursor.getInt(0)
tooltipId = cursor.getInt(1)
summary = cursor.getString(2)
detail = cursor.getString(3)
rowId = c.getInt(0)
tooltipId = c.getInt(1)
summary = c.getString(2)
detail = c.getString(3)
}

cursor = db.rawQuery(QUERY_TOOLTIP_BUTTONS, arrayOf(tooltipId.toString()))
database.rawQuery(QUERY_TOOLTIP_BUTTONS, arrayOf(tooltipId.toString())).use { c ->
while (c.moveToNext()) {
buttons.add(
Pair(
c.getString(0),
"http://localhost:6174/" + c.getString(1)
)
Comment thread
hal-eisen-adfa marked this conversation as resolved.
)
}
}

while (cursor.moveToNext()) {
buttons.add(
Pair(
cursor.getString(0),
"http://localhost:6174/" + cursor.getString(1)
)
Log.d(
TAG,
"For tooltip ${tooltipId}, retrieved ${buttons.size} buttons. They are $buttons."
)
}

Log.d(
TAG,
"For tooltip ${tooltipId}, retrieved ${buttons.size} buttons. They are $buttons."
)

cursor.close()
db.close()

} catch (e: Exception) {
Log.e(
TAG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -81,9 +82,14 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
* @param filePath = Current project colors file path;
*/
public void loadColorsFromXML(String filePath) throws FileNotFoundException {
InputStream stream = new FileInputStream(filePath);
colorParser = new ValuesResourceParser(stream, ValuesResourceParser.TAG_COLOR);
colorList = colorParser.getValuesList();
try (InputStream stream = new FileInputStream(filePath)) {
colorParser = new ValuesResourceParser(stream, ValuesResourceParser.TAG_COLOR);
colorList = colorParser.getValuesList();
} catch (FileNotFoundException e) {
throw e;
} catch (IOException e) {
e.printStackTrace();
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

private void setupDialogViews(LayoutValuesItemDialogBinding bind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -75,9 +76,14 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
* @param filePath = Current project strings file path;
*/
public void loadStringsFromXML(String filePath) throws FileNotFoundException {
InputStream stream = new FileInputStream(filePath);
stringParser = new ValuesResourceParser(stream, ValuesResourceParser.TAG_STRING);
stringList = stringParser.getValuesList();
try (InputStream stream = new FileInputStream(filePath)) {
stringParser = new ValuesResourceParser(stream, ValuesResourceParser.TAG_STRING);
stringList = stringParser.getValuesList();
} catch (FileNotFoundException e) {
throw e;
} catch (IOException e) {
e.printStackTrace();
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

public void addString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ValuesManager {

public static String getValueFromResources(String tag, String value, String path) {
String resValueName = value.substring(value.indexOf("/") + 1);
String result = null;
try {
ValuesResourceParser parser = new ValuesResourceParser(new FileInputStream(path), tag);
try (FileInputStream stream = new FileInputStream(path)) {
ValuesResourceParser parser = new ValuesResourceParser(stream, tag);

for (ValuesItem item : parser.getValuesList()) {
if (item.name.equals(resValueName)) {
result = item.value;
}
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ private void buildVectorModel() {
}
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
} finally {
if (vectorStream != null) {
try {
vectorStream.close();
} catch (IOException ignored) {
}
vectorStream = null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,14 @@ void buildVectorModel() {
}
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
} finally {
if (vectorStream != null) {
try {
vectorStream.close();
} catch (IOException ignored) {
}
vectorStream = null;
}
}
}

Expand Down
Loading