Skip to content

Use imports instead of inline fully-qualified names in the DSL compilers - #13975

Merged
wu-sheng merged 1 commit into
masterfrom
fix/dsl-inline-fqcn
Aug 11, 2026
Merged

Use imports instead of inline fully-qualified names in the DSL compilers#13975
wu-sheng merged 1 commit into
masterfrom
fix/dsl-inline-fqcn

Conversation

@wu-sheng

Copy link
Copy Markdown
Member

Use imports instead of inline fully-qualified names in the DSL compilers

CLAUDE.md bans fully-qualified class names written inline where an import would do, and names the
exact form found here:

Field declarations, method signatures, local variables, and generic type arguments should always
use the imported short name — private RemoteClientManager rcm;, not
private org.apache.skywalking...RemoteClientManager rcm;

Analyzer.java:242 was literally private javassist.ClassPool pool;. 44 sites across 14 files in
the four DSL modules: parameter and field types, locals, throws clauses, static calls, a class
literal and a method reference.

The part that needed care

Every site changed is a name the compiler resolves. Nothing resolved at runtime was touched.

That distinction is the whole risk. Javassist's compiler has no import statement — it resolves a
simple class name only against ClassPool.importedPackages, which holds java.lang and nothing
else. A fully-qualified name inside generated source is therefore mandatory, and shortening one
still compiles as Java, then fails when the rule is compiled. The same applies to anything handed
to Class.forName.

So this PR deliberately did not touch:

  • FQCNs inside codegen string literals (MAL/LAL/Hierarchy generators)
  • anything under code-templates-v2/*.ftl
  • names resolved reflectively

The transform rewrote only lines containing no quote character. That is sufficient rather than
merely convenient: a Java string literal cannot span lines under JDK 11, so a line with no quote
cannot be inside one. Verified after the fact — git diff shows no changed line contains a quote,
and no .ftl is modified.

Simple-name collisions and in-file shadowing were checked before any import was added. There were
none, so no site had to be left qualified for ambiguity.

Documentation

Adds a short CLAUDE.md to code-templates-v2/. The rule already exists in the root CLAUDE.md,
but the templates are the weakest spot: they are not Java, so a reader editing one has no reason to
consult a Java style rule, and "tidying" an FQCN there breaks the OAP only at rule-compile time.

  • Explain briefly why the bug exists and how to fix it.
  • If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes #.

No changelog entry: no behaviour change, no user-visible surface.

@wu-sheng wu-sheng added this to the 11.0.0 milestone Aug 11, 2026
@wu-sheng
wu-sheng force-pushed the fix/dsl-inline-fqcn branch from e5998cb to cc3b2e9 Compare August 11, 2026 05:50
CLAUDE.md bans fully-qualified class names written inline where an import would
do, and names the exact form Analyzer.java:242 used: a field declared as
`private javassist.ClassPool pool;`. 44 such sites across 14 files in the four
DSL modules -- parameter and field types, locals, throws clauses, static calls, a
class literal and a method reference.

Every one is a name the COMPILER resolves. Nothing resolved at runtime was
touched: no FQCN inside a codegen string literal, none in a FreeMarker template,
none handed to Class.forName or to Javassist. That distinction is the whole risk
here -- Javassist's compiler has no import statement and resolves simple names
only against java.lang, so shortening a name in generated source compiles as Java
and then fails when the rule is compiled.

The transform only rewrote lines containing no quote character, which is sufficient
rather than merely convenient: a Java string literal cannot span lines under JDK
11, so a line with no quote cannot be inside one. Simple-name collisions and
in-file shadowing were checked before any import was added; there were none.

Adds a short CLAUDE.md to code-templates-v2/ saying the templates must stay fully
qualified. Those files are the weakest spot, because they are not Java and a
reader editing one has no reason to consult a Java style rule.
@wu-sheng
wu-sheng force-pushed the fix/dsl-inline-fqcn branch from cc3b2e9 to 9a67277 Compare August 11, 2026 06:00
@wu-sheng
wu-sheng merged commit 092dd69 into master Aug 11, 2026
451 of 456 checks passed
@wu-sheng
wu-sheng deleted the fix/dsl-inline-fqcn branch August 11, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants