Skip to content

Commit dc9af16

Browse files
author
OpenMoTa3
authored
Merge branch 'tyron12233:main' into main
2 parents 2f024d2 + 41d146c commit dc9af16

6 files changed

Lines changed: 94 additions & 13 deletions

File tree

‎.github/badges/tests.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"schemaVersion": 1,
33
"label": "tests",
4-
"message": "2444 passing",
4+
"message": "2445 passing",
55
"color": "brightgreen"
66
}

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ on each release.
109109
## Tests
110110

111111
<!-- AUTOGEN:tests:START -->
112-
**2444** tests passing across **401** suites · 0 failing · 2 skipped (framework / `CI_CORE_ONLY`).
112+
**2445** tests passing across **401** suites · 0 failing · 2 skipped (framework / `CI_CORE_ONLY`).
113113
<!-- AUTOGEN:tests:END -->
114114

115115
The badges and the numbers in this section are regenerated automatically on each release (see

‎analytics-api/src/main/kotlin/dev/ide/analytics/CrashScrub.kt‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ object CrashScrub {
1414
var ownPackagePrefixes: List<String> = listOf("dev.ide.")
1515
private const val MAX_FRAMES = 30
1616

17+
/**
18+
* Platform/library packages that are safe to name when a crash has NONE of our own frames anywhere (neither
19+
* the exception nor its cause chain). These hold no user data — the user's program runs on the interpreter
20+
* VM, never as real host JVM frames — so a `kotlin.collections.CollectionsKt.first` or
21+
* `androidx.compose.*` frame is a class+method+line of the framework, not PII. Without this, a crash buried
22+
* entirely in framework code reports an EMPTY `frames` and is untriageable (we saw a large `NoSuchElement`/
23+
* `ClassCast` cluster with nothing to act on). Bounded to a few top frames of the deepest cause.
24+
*/
25+
private val platformPackagePrefixes: List<String> = listOf(
26+
"androidx.", "android.", "java.", "javax.", "kotlin.", "kotlinx.",
27+
"org.jetbrains.", "com.google.", "com.android.", "dalvik.", "sun.", "libcore.",
28+
)
29+
private const val MAX_FALLBACK_FRAMES = 8
30+
1731
/** `{exception: "Type <- CauseType <- …", frames: "Class.method:line\n…"}` — scrubbed. */
1832
fun scrub(t: Throwable): Map<String, String> = mapOf(
1933
"exception" to exceptionChain(t),
@@ -50,12 +64,18 @@ object CrashScrub {
5064
// A deep framework crash (Compose runtime, Android looper) can bury the first of OUR frames past the
5165
// cap — or entirely, with our code only on the cause chain — leaving an untriageable report (we saw a
5266
// large share of crashes with no own frame at all). Guarantee the deepest own frame anywhere in the
53-
// exception's own trace or its causes, so every crash pins to a call site we can act on.
54-
if (!anyOwn) deepestOwnFrame(t)?.let { out.add(it) }
67+
// exception's own trace or its causes, so every crash pins to a call site we can act on. If there is no
68+
// own frame ANYWHERE, fall back to the deepest cause's top platform frames so the crash site is still
69+
// visible instead of an empty report.
70+
if (!anyOwn) {
71+
val own = deepestOwnFrame(t)
72+
if (own != null) out.add(own) else out.addAll(platformFallbackFrames(t))
73+
}
5574
return out.joinToString("\n")
5675
}
5776

5877
private fun isOwn(f: StackTraceElement) = ownPackagePrefixes.any { f.className.startsWith(it) }
78+
private fun isPlatform(f: StackTraceElement) = platformPackagePrefixes.any { f.className.startsWith(it) }
5979
private fun frame(f: StackTraceElement) = "${f.className}.${f.methodName}:${f.lineNumber}"
6080

6181
/** The first own frame found walking the exception and its cause chain (cycle-guarded); null if none. */
@@ -68,4 +88,22 @@ object CrashScrub {
6888
}
6989
return null
7090
}
91+
92+
/**
93+
* When no own frame exists anywhere, the top platform frames of the deepest cause (the actual origin) — so
94+
* a crash that lives entirely in framework/stdlib code still reports WHERE it threw. Privacy-safe: only
95+
* recognized platform packages, class+method+line, no messages. Empty if the trace has no platform frame.
96+
*/
97+
private fun platformFallbackFrames(t: Throwable): List<String> {
98+
val chain = ArrayList<Throwable>()
99+
val seen = HashSet<Throwable>()
100+
var cur: Throwable? = t
101+
while (cur != null && seen.add(cur)) { chain.add(cur); cur = cur.cause }
102+
for (e in chain.asReversed()) { // deepest cause first
103+
val frames = e.stackTrace.asSequence().filter { isPlatform(it) }.take(MAX_FALLBACK_FRAMES)
104+
.map { frame(it) }.toList()
105+
if (frames.isNotEmpty()) return frames
106+
}
107+
return emptyList()
108+
}
71109
}

‎analytics-impl/src/test/kotlin/dev/ide/analytics/impl/AnalyticsTest.kt‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ class AnalyticsTest {
119119
assertEquals("dev.ide.core.Foo.bar:42", dev.ide.analytics.CrashScrub.ownFrames(top))
120120
}
121121

122+
@Test
123+
fun crashWithNoOwnFrameAnywhereFallsBackToPlatformFrames() {
124+
// A crash buried ENTIRELY in framework/stdlib code (e.g. NoSuchElementException from an empty-list
125+
// access inside a Compose lambda that R8 inlined our frame out of): no dev.ide.* frame anywhere. The
126+
// scrubber must surface the top platform frames of the deepest cause instead of an empty report.
127+
val boom = NoSuchElementException("List is empty.").apply {
128+
stackTrace = arrayOf(
129+
StackTraceElement("kotlin.collections.CollectionsKt___CollectionsKt", "first", "_Collections.kt", 233),
130+
StackTraceElement("androidx.compose.runtime.ComposerImpl", "recompose", "Composer.kt", 3210),
131+
StackTraceElement("android.os.Handler", "dispatchMessage", "Handler.java", 99),
132+
)
133+
}
134+
val frames = dev.ide.analytics.CrashScrub.ownFrames(boom)
135+
assertTrue(frames.isNotEmpty(), "must not be empty when only platform frames exist")
136+
assertTrue(frames.startsWith("kotlin.collections.CollectionsKt___CollectionsKt.first:233"), "surfaces the origin: $frames")
137+
// still no messages leaked
138+
val props = dev.ide.analytics.CrashScrub.scrub(boom)
139+
assertFalse((props.values.joinToString(" ")).contains("List is empty"), "no exception message: $props")
140+
}
141+
122142
@Test
123143
fun analyticsLogSinkForwardsErrorsScrubbedAndThrottled() {
124144
val sink = FakeSink()

‎ide-android/build.gradle.kts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ android {
270270
minSdk = 26
271271
targetSdk = 36
272272
// versionCode must exceed the last published release (the previous-codebase app reached ~29).
273-
versionCode = 63
274-
versionName = "3.7.3"
273+
versionCode = 64
274+
versionName = "3.7.4"
275275
// connectedAndroidTest harness (the on-device Kotlin-compiler discovery spike).
276276
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
277277

@@ -308,6 +308,7 @@ android {
308308
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("compose-runtime-asset").get().asFile)
309309
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("compose-fonts-asset").get().asFile)
310310
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("compose-strings-asset").get().asFile)
311+
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("agent-ui-strings-asset").get().asFile)
311312
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("compose-drawables-asset").get().asFile)
312313
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("r8-dex-asset").get().asFile)
313314
sourceSets.getByName("main").assets.srcDir(layout.buildDirectory.dir("applog-runtime-asset").get().asFile)
@@ -628,7 +629,7 @@ val fetchAndroidBuildTools = tasks.register("fetchAndroidBuildTools") {
628629
// Run before anything AGP does, so the freshly-fetched lib*.so are on disk when the native-lib merge runs,
629630
// and the staged kotlin-stdlib.jar asset is present when the asset merge runs.
630631
tasks.named("preBuild").configure {
631-
dependsOn(fetchAndroidBuildTools, bundleKotlinStdlibAsset, bundleKotlincResourcesAsset, bundleComposeRuntimeAsset, bundleComposeFontsAsset, bundleComposeStringAsset, bundleComposeDrawablesAsset, bundleR8DexAsset, bundleAppLogRuntimeAsset, bundleVmSpikeComposeRuntimeAsset)
632+
dependsOn(fetchAndroidBuildTools, bundleKotlinStdlibAsset, bundleKotlincResourcesAsset, bundleComposeRuntimeAsset, bundleComposeFontsAsset, bundleComposeStringAsset, bundleAgentUiComposeStringAsset, bundleComposeDrawablesAsset, bundleR8DexAsset, bundleAppLogRuntimeAsset, bundleVmSpikeComposeRuntimeAsset)
632633
}
633634

634635
// Same Android packaging gap as the fonts above, for the i18n string resources. :ide-ui's
@@ -646,6 +647,20 @@ val bundleComposeStringAsset = tasks.register<Copy>("bundleComposeStringAsset")
646647
into(layout.buildDirectory.dir("compose-strings-asset/composeResources/dev.ide.ui.generated.resources"))
647648
}
648649

650+
// The SAME Android packaging gap, for :agent-ui's OWN compose-resource strings (the chat_* i18n keys, which
651+
// live in this module's composeResources under package dev.ide.agent.ui.generated.resources — migrated out of
652+
// :ide-ui). Its compiled `.cvr` files must be staged under THAT resClass-package segment; without this the
653+
// agent chat panel crashes on device with `MissingResourceException: composeResources/
654+
// dev.ide.agent.ui.generated.resources/values/strings.commonMain.cvr`. Mirrors bundleComposeStringAsset.
655+
val bundleAgentUiComposeStringAsset = tasks.register<Copy>("bundleAgentUiComposeStringAsset") {
656+
description = "Stage :agent-ui's i18n compose-resource strings into the APK assets (Android packaging gap)."
657+
dependsOn(":agent-ui:desktopProcessResources")
658+
from(project(":agent-ui").layout.buildDirectory.dir("processedResources/desktop/main/composeResources/dev.ide.agent.ui.generated.resources")) {
659+
include("values*/**/*.cvr")
660+
}
661+
into(layout.buildDirectory.dir("agent-ui-strings-asset/composeResources/dev.ide.agent.ui.generated.resources"))
662+
}
663+
649664
// The stock Eclipse jars we relocate for ART (ecj, core.runtime, equinox.common) reach the app's runtime
650665
// classpath through several project dependencies: :ide-core (excluded inline below), but also :android-support
651666
// and :layout-preview-impl, which depend on :lang-jdt without that exclude. Dexing both the stock jar and its

‎ide-ui/src/commonMain/kotlin/dev/ide/ui/editor/EditorRendering.kt‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,27 @@ internal fun DrawScope.drawEditor(
174174
val l = layoutFor(line)
175175
val top = lineTop(line)
176176
val marker = if (trailingMarker) metrics.charWidth * 0.6f else 0f
177+
// Callers pass columns derived from offsets remembered against the document (selection, find/occurrence
178+
// matches, template fields). A one-frame-stale offset can land a column past the freshly laid-out line's
179+
// end, and getHorizontalPosition/getLineForOffset throw on an out-of-range column (seen in the wild as an
180+
// IllegalArgumentException from this draw path). Clamp into the layout like xOf does; vEnd == -1 is the
181+
// "to end of line" sentinel and must survive the clamp.
182+
val maxCol = l.layoutInput.text.length
183+
val startCol = vStart.coerceIn(0, maxCol)
184+
val endCol = if (vEnd < 0) -1 else vEnd.coerceIn(0, maxCol)
177185
if (!wrap) {
178-
val x0 = textLeft + l.getHorizontalPosition(vStart, usePrimaryDirection = true)
179-
val x1 = if (vEnd >= 0) textLeft + l.getHorizontalPosition(vEnd, usePrimaryDirection = true)
186+
val x0 = textLeft + l.getHorizontalPosition(startCol, usePrimaryDirection = true)
187+
val x1 = if (endCol >= 0) textLeft + l.getHorizontalPosition(endCol, usePrimaryDirection = true)
180188
else textLeft + l.size.width + marker
181189
if (x1 > x0) drawRect(color, Offset(x0, top), Size(x1 - x0, lineH))
182190
return
183191
}
184-
val firstSub = l.getLineForOffset(vStart)
185-
val lastSub = if (vEnd >= 0) l.getLineForOffset(vEnd) else (l.lineCount - 1).coerceAtLeast(0)
192+
val firstSub = l.getLineForOffset(startCol)
193+
val lastSub = if (endCol >= 0) l.getLineForOffset(endCol) else (l.lineCount - 1).coerceAtLeast(0)
186194
for (s in firstSub..lastSub) {
187-
val x0 = textLeft + (if (s == firstSub) l.getHorizontalPosition(vStart, usePrimaryDirection = true) else l.getLineLeft(s))
195+
val x0 = textLeft + (if (s == firstSub) l.getHorizontalPosition(startCol, usePrimaryDirection = true) else l.getLineLeft(s))
188196
val x1 = textLeft + when {
189-
s == lastSub && vEnd >= 0 -> l.getHorizontalPosition(vEnd, usePrimaryDirection = true)
197+
s == lastSub && endCol >= 0 -> l.getHorizontalPosition(endCol, usePrimaryDirection = true)
190198
else -> l.getLineRight(s) + if (s == lastSub) marker else 0f
191199
}
192200
if (x1 > x0) drawRect(color, Offset(x0, top + s * lineH), Size(x1 - x0, lineH))

0 commit comments

Comments
 (0)