| name | cwe-369-divide-by-zero |
| description | Use this skill when you need to remediate CWE-369 (Divide By Zero) vulnerabilities in Java code. Triggers on SAST findings, security reviews, or when fixing divide by zero issues. |
| version | 1.0.0 |
| license | MIT |
| tags | ["security","java","cwe-369","remediation","sast"] |
CWE-369 Divide By Zero
Description
Divide By Zero
Reference:
https://cwe.mitre.org/data/definitions/369.html
OWASP Category: A03:2021 – Injection
Vulnerable Pattern
❌ Example 1: Vulnerable Pattern
int result = total / count;
Why it's vulnerable: This pattern is vulnerable to Divide By Zero
Deterministic Fix
✅ Secure Implementation: Secure Implementation
if (count == 0) {
throw new IllegalArgumentException("Division by zero");
}
int result = total / count;
Why it's secure: Implements proper protection against Divide By Zero
Detection Pattern
Look for these patterns in your codebase:
grep -rn "/[^/*]\\|% " --include="*.java" | grep -v "//"
Remediation Steps
-
Always check divisor is not zero before division
-
Handle zero case explicitly with default value or exception
Key Imports
Verification
After remediation:
-
Run SAST scanner to confirm vulnerability is resolved
-
Review all instances of the vulnerable pattern
-
Add unit tests that verify the secure implementation
-
Check for similar patterns in related code
Trigger Examples
Fix CWE-369 vulnerability
Resolve Divide By Zero issue
Secure this Java code against divide by zero
SAST reports CWE-369
Common Vulnerable Locations
| Controller | *Controller.java | User input handling |
| Service | *Service.java | Business logic |
| Repository | *Repository.java | Data access |
References
Source: Generated by Java CWE Security Skills Generator
Last Updated: 2026-03-07