Safeguard
Security Guides•

How does SAST work for Java, and does it need a build?

Java SAST often analyzes compiled bytecode, so it may need a successful build first. What it finds, what that means for CI and how to set it up.

Safeguard Security Team
3 min read

Some Java SAST tools analyze compiled bytecode, others analyze source, and several do both. If a tool works on compiled classes, it needs a successful build first, which affects where you run it in CI and how fast feedback arrives.

Source analysis versus bytecode analysis

SpotBugs, a free static analysis tool for Java, states that it can analyze programs compiled for any version of Java, which indicates it works on compiled programs. It checks for more than 400 bug patterns, runs on JRE or JDK 11 or later, and supports extensions that add detectors, including the find-sec-bugs security plugin.

ApproachNeeds a buildStrengthWeakness
Source analysisOften notFast, works on partial codeWeaker on resolved types and libraries
Bytecode analysisYesSees resolved types and generated codeSlower, needs working build
BothDependsBroadest viewMore setup

What Java SAST typically flags

  • SQL built by string concatenation instead of prepared statements.
  • Unsafe deserialization of untrusted streams. See Java deserialization allowlists.
  • XML parsers with external entities enabled.
  • Weak or misused cryptography.
  • Path traversal and command execution from input.
  • Hardcoded passwords.

Frameworks matter. Injection in a Spring controller or a servlet is traced through framework annotations, so check the tool supports the framework you use. See checking SAST language and framework coverage.

Steps

  1. Make sure the project builds in a clean CI environment. This is the most common blocker.
  2. Run the scan after the compile step and keep the build outputs available to the scanner.
  3. Start with a baseline and fail only on new high severity findings.
  4. Review the framework specific findings first, since they are usually the most real.
  5. Add dependency scanning for Maven or Gradle. Most Java risk lives in libraries.

Common blockers

Generated sources that are not on the path, multi module builds scanned module by module, and private repositories the CI cannot reach. Each causes missed code without an obvious error, so compare the file count scanned with the file count you expect.

How Safeguard helps

Safeguard provides SBOM and dependency scanning with reachability analysis, and policies, gates and guardrails you can apply before merge. You can try the free scan on a repository.

Quick check

Why does my Java scan say nothing was analyzed?

Often the build did not run or the compiled output was not available to the scanner. Check the build step first.

Is source analysis worse than bytecode analysis?

Not worse, different. Source analysis is faster; bytecode analysis sees resolved types. Many teams use both.

Sources

  • SpotBugs project site (fetched 19 October 2026): bug patterns, JRE requirement, plugin support.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.