Repository navigation
Description
Found by the Batch A regen in keyword-rosetta (gitgalaxy#2669 A.5), while attributing a new red cell: apex import read 6 against a cross-language median of 3.
The defect
LANGUAGE_DEFINITIONS["apex"]["rules"]["import"] is:
\bType\.forName\b|(?!(?:System|Database|Schema|Auth|Cache|Chatter|EventBus|Limits|Messaging|RestContext|Test)\b)\b[a-zA-Z_]\w*\.[A-Z]\w*\b
compiled with re.IGNORECASE. The second alternative is clearly meant to catch a type reference — lowercase receiver, capitalised member — but re.IGNORECASE applies to the whole pattern, so [A-Z] matches any letter and the alternative degrades to "any word.word". Every method call in an Apex file is therefore counted as an import.
Micro-repro (live registry, engine 3ac9182):
foo.bar -> ["foo.bar"] # should not match
conn.clear -> ["conn.clear"] # should not match
Logger.info -> ["Logger.info"] # should not match
System.debug -> [] # correctly excluded by the lookahead
Database.query -> [] # correctly excluded by the lookahead
Recompiling the identical pattern without re.IGNORECASE returns [] for all three of the first group, which isolates the flag as the whole cause.
Scanned every language: apex is the only rule that combines re.IGNORECASE with an [A-Z] guard, so the blast radius is apex alone.
Why it surfaced now
The keyword-rosetta corpus expresses the SPEC dependency chain main->a->b->c as Type.forName(...), planted in #2669 A.3 (apex previously had no chain at all). That is +1 legitimate import per planting file. The corpus also contains ordinary Apex code — Logger.info, Log.error in b.cls, conn.clear in c.cls — and those three incidental method calls are counted as imports too:
| file | matches |
|---|---|
| main.cls | Type.forName |
| a.cls | Type.forName |
| b.cls | Type.forName, Logger.info, Log.error |
| c.cls | conn.clear |
= 6 against a planted intent of 3. Before A.3 the count coincidentally read 3 (the three incidental hits with no chain), which is why nothing caught it earlier — the number was right for the wrong reason.
Fix shape
Keep re.IGNORECASE — Apex is a case-insensitive language and Type.forName genuinely needs it — but scope the capital-letter guard, e.g. (?-i:[A-Z]) on the member segment, or split the alternation so only the Type.forName arm is case-insensitive. Strict tests should cover:
- positive:
Type.forName(...),TYPE.FORNAME(...), a real type referenceAccount.SObjectType - negative:
foo.bar,conn.clear,Logger.info,System.debug,Database.query
Same family as #2544 (swift open counted from prose) — a rule whose guard does not actually guard.
Corpus side
Not worked around: Logger.info/Log.error/conn.clear are ordinary Apex and deleting them would hide the defect. The red cell is ledgered in keyword-rosetta as apex-import-ignorecase-type-guard so the Batch A bless has an explanation, and the manifest keeps the observed 6. Once this lands, apex re-blesses to import 3 (the chain alone).
Collected by #2669 B.1/B.3.
Activity
regen: Batch A bias report (#2669 A.5)
squid-protocol commentedon Sep 2, 2026
Not the same rule as #2672 (that is the
docmarker/tag double-count family), but the same one-regex/one-strict-test shape and the same apex definition file — #2672 recommends B.3 carry both in one PR.fix(core-engine): Rosetta batch 3 wave 2 — doc-comment pairing, rule …
squid-protocol commentedon Sep 3, 2026
Closing: verified fixed on main. The apex
importrule's type guard holds again —account.nameandmyvar.fieldare no longer counted as imports, whileType.forName(x)still is. Landed in #2681 (Batch B.3 wave 2 of #2669). Worth noting for anyone re-checking: the rule still compiles withre.IGNORECASE, so a flag check alone reads as unfixed; the guard was restructured instead, and only a behavioural test shows it.fix(core-engine): four metric defects — tcl body slicing, groovy/apex…
import contract (#2875): state the rule contract, edit 15 rules on it…