baseline-java — Claude Code rule: Java checks
The baseline-java Claude Code rule adds Java checks for security, concurrency, and exception handling. It applies during Java code review.
MIT ★ 517 updated 2026-11-16
.claude/rules/baseline-java.mdWhat baseline-java does
The rule flags SQL built by string concatenation, credentials embedded in source, and untrusted content passed to HTML rendering. It also checks calls to Runtime.exec and ProcessBuilder, along with logs that may expose sensitive fields.
Other checks cover shared SimpleDateFormat instances, thread-pool factories that can create unbounded resources, and empty catch blocks. Authorization needs a manual semantic check: queries for user data should include the current user or tenant, not just a business ID. The rule set can be edited for a project’s stack without changing the orchestration logic in SKILL.md.
What it helps with
- spot SQL statements assembled through string concatenation
- find credentials embedded in Java source
- flag logs that expose sensitive values
- catch empty exception handlers and shared date formatters
- check whether user-data queries include a user or tenant condition
Example prompts for the agent
- Review this Java code for security and concurrency issues.
- Find credentials in the Java source and sensitive values in logs.
- Check user-data queries for an authorization condition.
How to install baseline-java
Manually: put the files in place
.claude/rules/baseline-java.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/baseline-java.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/baseline-java.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/baseline-java.mdManually: put the files in place
.clinerules/baseline-java.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about baseline-java
How do I install baseline-java in Claude Code?
Add the rule file at .claude/rules/baseline-java.md.
What does baseline-java do?
It checks Java code for common security, concurrency, and exception-handling issues, including unsafe SQL construction, exposed credentials, and empty catch blocks.
How does baseline-java check query authorization?
That check is semantic and manual. A query for user data should include userId or tenantId, rather than filtering only by orderId or id.
Source text
baseline-java.md · MIT
# Common baseline (Java)
A minimal usable rule set covering three high-frequency categories: security, concurrency, and exceptions.
Add or remove rules according to the project's actual stack; replacing this file does not affect the orchestration logic in `SKILL.md`.
## Security
### SEC-001 [HIGH] SQL string concatenation
SQL must use parameter binding; user input must never be concatenated into statements.
**Detection pattern** (any hit is a violation):
- `Statement[^;]*execute(Query|Update)?\s*\(\s*["'][^"']*["']\s*\+`
- `create(Query|NativeQuery)\s*\(\s*["'][^"']*["']\s*\+`
- `["'][^"']*(SELECT|INSERT|UPDATE|DELETE)[^"']*["']\s*\+`
### SEC-002 [HIGH] Hard-coded credentials
Passwords, keys, and tokens must not be written in source code.
**Detection pattern**:
- `(password|passwd|secret|token|apiKey|accessKey|privateKey)\s*=\s*"[^"]{6,}"`
### SEC-003 [HIGH] Dangerous XSS rendering
Untrusted content must not be passed directly to HTML rendering.
**Detection pattern**:
- `v-html|dangerouslySetInnerHTML|innerHTML\s*=`
### SEC-004 [HIGH] Command execution
Confirm that arguments do not come from user input before invoking a system command.
**Detection pattern**:
- `Runtime\.getRuntime\(\)\.exec\s*\(|new\s+ProcessBuilder\s*\(`
### AUTH-001 [HIGH] Missing authorization on queries
**Detection mode**: semantic
When querying user data by business ID, include the current user or tenant condition as well.
**Detection pattern**: none (manual check: whether the query condition contains only orderId / id, with no userId / tenantId)
## Logging and data
### LOG-001 [HIGH] Sensitive fields in logs
ID card numbers, phone numbers, bank card numbers, passwords, and tokens must not appear in logs in plaintext.
**Detection pattern**:
- `log(ger)?\.(info|debug|warn|error)\([^)]*(idCard|idNo|phone|mobile|bankCard|password|token)`
## Concurrency and exceptions
### CONC-001 [HIGH] Shared SimpleDateFormat
`SimpleDateFormat` is not thread-safe and must not be used as a static shared instance.
**Detection pattern**:
- `static\s+(final\s+)?SimpleDateFormat`
### CONC-002 [MEDIUM] Thread pool without explicit bounds
`Executors` factory methods can easily create unbounded queues or unlimited threads.
**Detection pattern**:
- `Executors\.(newCachedThreadPool|newFixedThreadPool)\s*\(`
### ERR-001 [HIGH] Empty catch swallows exceptions
An empty catch block fails silently; it must at least log the exception or rethrow it.
**Detection pattern**:
- `catch\s*\([^)]*\)\s*\{\s*\}`
© kyy-logs · MIT · kyy-logs/code-review-gate-skill