Chapter 01Lesson 01~100 minutes

Static Analysis, Clean Code, Technical Debt, and Quality Governance: Core Concepts and Mental Model

Build the mental model for governed static analysis: what SonarQube can observe, which state owns each result, and how rules, measures, New Code, quality gates, and human decisions become trustworthy delivery evidence.

Static analysisClean CodeQuality governanceTechnical debtEvidence

Learning objectives

  • Separate source revision, scanner/analyzer execution, server processing, project policy, and governance state.
  • Trace one source revision through rules and analysis into findings, measures, a quality-gate result, and a delivery decision.
  • Distinguish static analysis evidence from proof of functional correctness or complete security.
  • Explain why technical-debt estimates, issue counts, and severities are decision inputs rather than developer scores.
  • Interpret Standard Experience and MQR Mode terminology without mixing their issue classifications.

1. Current baseline, scope, and safety boundary

This chapter starts with governance rather than administration. The executable examples use SonarQube Community Build 26.9.0.129388, the current Community Build release checked on 2026-09-07. Community Build is sufficient for the mandatory path: a learner can analyze a synthetic repository, inspect findings and measures, review the active quality profile, reason about New Code, and observe a quality-gate result without a commercial license.

Community Build currently supports two ways of expressing rule impact: Standard Experience and Multi-Quality Rule (MQR) Mode. The same rule set can be classified differently after a mode change, so a governance record must state which mode and product version produced its evidence.

Safety boundary: analyze only the synthetic repository supplied in this chapter or another repository you are explicitly authorized to inspect. Do not upload proprietary source, production secrets, customer data, private certificates, real tokens, or internal URLs into a learning instance or evidence packet.

2. The problem static analysis actually solves

A codebase can compile and its tests can pass while still containing maintainability hazards, suspicious control flow, insecure constructs, duplicated logic, or patterns that make future change riskier. Static analysis examines source and related analysis inputs without executing the application as a user workload. Its job is to expose evidence that humans and delivery automation can review consistently.

That evidence has a boundary. A clean analysis does not prove that business logic is correct, that every runtime path is safe, that production dependencies are uncompromised, or that no attacker can exploit the system. Static analysis complements tests, reviews, dependency controls, runtime monitoring, and security assessment; it does not replace them.

Technique Question it can answer well Typical blind spot
Static analysis Does the source match known rule patterns and quality/security expectations? Runtime-only behavior, real traffic, environment state.
Unit/integration tests Does executed behavior satisfy specified examples/contracts? Unexecuted paths and many structural quality patterns.
Dynamic/security testing How does a running system behave under interaction or attack simulation? May not explain source-level maintainability structure.
Human review Does the change make architectural and business sense? Consistency and scale without automated support.

3. Mental model: risk to governed evidence

One analysis-and-governance evidence chain

Follow the arrows as ownership changes. A later green gate is meaningful only if you can still identify the revision and policy that created it.

flowchart TD
R[Business and code risk] --> S[Exact source revision]
S --> P[Effective quality profile and rules]
P --> A[Scanner and analyzers]
A --> U[Analysis report upload]
U --> C[Compute Engine/background processing]
C --> E[Issues and measures]
E --> N[New Code context]
N --> G[Quality gate]
G --> D[Human or CI delivery decision]
D --> O[Ownership, exception, and audit record]

Business/code risk defines what the team cares about. An exact source revision anchors all later evidence to a commit rather than a moving folder. A quality profile selects active rules for a language. The scanner indexes eligible source and coordinates analyzers, then uploads an analysis report. Server-side background processing turns that report into durable project results. Issues are individual rule findings; measures are aggregated observations such as size, duplication, or maintainability-related values. New Code defines which recent change set receives the strongest Clean-as-You-Code focus. A quality gate evaluates configured conditions. The gate then informs—not replaces—the delivery decision.

4. State stores you must not blur together

If a result looks wrong, asking “which state owns this fact?” is more useful than clicking around the UI.

State Owner Examples Diagnostic question
Source/revision Git/workspace commit SHA, files, generated/ignored paths Did we analyze the code we think we analyzed?
Scanner/runtime scanner/build process scanner version, Java, indexed files, effective parameters Did the client produce and upload the intended report?
Analysis task SonarQube server report task ID, queue/background-task status Was uploaded evidence processed successfully?
Project result SonarQube project issues, measures, analysis timestamp What durable result belongs to this analysis?
Policy project/quality admin quality profile, New Code definition, gate Which standards were actually effective?
Credential/trust SonarQube + secret store/network token scope, URL, TLS trust Was the analysis authorized through the intended trust boundary?
CI/provider CI/SCM job, artifact, commit, status check What did the delivery platform conclude?
Governance team/process owner, rationale, exception, expiry Who owns the policy and any deviation?

5. Rules, profiles, issues, measures, and gates

A rule describes a source pattern the analyzer can evaluate. A quality profile is the active rule set for a language. When analyzed code violates an active rule, SonarQube can create an issue. A metric defines what can be measured; a measure is a value for that metric on a specific project/analysis. A quality gate is a policy decision over selected measures/conditions. These objects are related, but they are not interchangeable.

Governance rule: never report “we have 37 issues” without also identifying the revision, analysis date, product mode/version, active profile, New Code definition, and gate. Raw counts without policy context invite false comparisons.

6. Clean Code and Clean-as-You-Code are operating ideas, not slogans

Clean Code guidance describes code qualities that make software easier and safer to evolve. Clean-as-You-Code turns that into an operational strategy: protect the code being changed now instead of requiring a team to repair every historical issue before it can ship anything. This is especially important for a legacy repository where “all existing code must be perfect immediately” can create a permanently red gate and encourage teams to game the policy.

New Code is the comparison window that gives this strategy a concrete boundary. Later chapters configure it in detail. For now, the key mental model is that new-code policy answers “what must this change avoid introducing?”, while overall-code measures answer “what inherited condition still exists?” Both can matter, but they serve different governance questions.

7. Standard Experience versus MQR Mode

Current Community Build can represent findings using Standard Experience categories or MQR Mode software-quality impacts. Standard Experience uses the familiar bug, vulnerability, and code-smell framing. MQR Mode expresses impacts across reliability, security, and maintainability, and one rule can affect more than one software quality. The severity vocabulary also differs.

A mode switch can therefore change displayed classifications, issue counts by category, and potentially gate evaluation. A mature program records the mode and reviews policy effects before changing it. Do not write automation that assumes a label such as “code smell” exists forever independently of mode.

8. Technical debt: useful estimate, dangerous accounting fiction

SonarQube maintainability measures can aggregate remediation effort: an estimated effort associated with resolving maintainability findings. Technical-debt ratio relates that estimated remediation cost to an estimated development cost. Those values help compare patterns under a consistent model. They are not invoices, developer productivity measurements, or promises about how many calendar hours a team will actually spend.

Actual remediation cost depends on architecture, domain knowledge, test coverage, dependency risk, review, deployment constraints, and whether the code should be redesigned rather than mechanically changed. Treat the metric as a model with assumptions, not an accounting ledger.

9. Security hotspot is not a vulnerability

A security hotspot points to security-sensitive code that requires human review to decide whether it is actually safe in context. A vulnerability/security issue represents a discovered problem with security impact that needs remediation. Conflating them damages triage: calling every hotspot a vulnerability inflates risk, while dismissing an actual vulnerability as “just a review item” understates risk.

10. Read-only inspection before policy changes

On any existing SonarQube project, start by recording rather than editing. Capture the project key and latest analysis/revision identity, current mode, effective quality profile(s), issue populations, selected measures, New Code definition, quality gate and result, and any ownership/exception record. If you cannot explain those facts, you are not ready to change thresholds or suppress findings.

Evidence card

Project key · revision · product version/edition · mode · scanner identity · profile(s) · New Code definition · gate · gate status · owner · exceptions/expiry.

11. Foundation mistakes that corrupt the signal

  • “No findings means correct and secure.” Static analysis has scope and rule coverage; absence of findings is not proof.
  • “Enable every rule.” More rules can create noise, incompatible expectations, and review fatigue. Activate a coherent standard deliberately.
  • “Issue count ranks developers.” Counts depend on language, code size, change type, profile, mode, age, and context. They are not individual performance scores.
  • “Debt is money/time owed.” Remediation effort is a modeled estimate.
  • “Legacy code must be perfect before any merge.” Without a New Code strategy, teams can get trapped behind inherited debt.
  • “Every hotspot is exploitable.” A hotspot is a review workflow, not automatic vulnerability proof.

12. Hands-on lab: write a quality-governance charter before scanning

  1. Create a temporary folder named sq-ch01-charter and initialize an empty Git repository.
  2. Create QUALITY_CHARTER.md with: business risk, in-scope languages/repositories, source-revision rule, default quality standard, New Code intent, gate intent, security-review responsibility, exception owner/expiry, and evidence-retention expectations.
  3. Add the charter and commit it. Record git rev-parse HEAD. This revision is the first governance artifact in the chapter.
  4. Predict which facts a future scan must add: scanner/runtime identity, indexed files, task ID, project result, gate result. Mark each as not yet observed rather than inventing values.
  5. Review the charter for any developer-ranking metric, “zero findings = secure” claim, permanent exception, or proprietary-data requirement. Remove those anti-patterns.

This lab intentionally stops before installation. The next lesson adds a disposable local server and scanner so you can test whether the evidence chain matches your predictions.

13. Why this matters in DevOps

A CI quality check is a delivery control. Controls are trustworthy only when their inputs, policy, asynchronous result, owner, and exceptions are traceable. The operational skill is therefore not “find the Quality Gate screen”; it is prove which revision was analyzed under which standard and why the resulting decision is appropriate.

Knowledge check

Why can a green quality gate not prove an application is functionally correct?

What is the difference between a quality profile and a quality gate?

Why must a report record Standard Experience or MQR Mode?

A security hotspot appears. Is it automatically a vulnerability?

What is wrong with ranking engineers by technical-debt or issue totals?

Next lesson

From governance charter to a complete local evidence chain

Lesson 2 creates a synthetic repository, runs a pinned Community Build analysis, preserves scanner and task evidence, and compares predictions with the actual project result.

Official references and version notes

Version and compatibility note

Version-sensitive statements were rechecked against current SonarSource primary documentation on 2026-09-07. The executable local path in this chapter pins SonarQube Community Build 26.9.0.129388 with official image sonarqube:26.9.0.129388-community. Where a standalone SonarScanner CLI is used, the lab records 8.1.0.6389 from SonarSource update-center metadata. Current scanner Java/JRE auto-provisioning behavior and exact bootstrap requirements must be rechecked at execution time. Commercial SonarQube Server/Data Center and SonarQube Cloud features are not required for this chapter.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.