claude-skills/engineering-team/skills/code-reviewer/assets/sample_java_clean.java
Claude 5ff4375603
feat(code-reviewer): wire Java into analyzer + complete the refactor
Builds on @mitnick2012's universal+per-language restructure (PR #742).

- Add Java as a first-class deterministic language in code_quality_checker.py
  (LANGUAGE_EXTENSIONS + function/class/method patterns + check_java_specific_smells),
  so the documented `--language java` command works instead of erroring on an
  invalid choice. Add Java debug + @SuppressWarnings signals to pr_analyzer.py.
- Add Java regression fixtures (sample_java_smells/clean.java) with committed
  expected_outputs JSON, mirroring the existing C# fixtures.
- Delete references/{code_review_checklist,coding_standards,common_antipatterns}.md,
  now duplicated by rules/universal.md + languages/*.md; repoint README and the
  C# clean fixture header at the new structure.
- Document the optional analyzer-wiring + fixture steps in the "Adding a New
  Language" guide and restore a Regression Fixtures section in SKILL.md.

https://claude.ai/code/session_01DjuELpoFdFbFscr3kAatni
2026-05-26 14:02:19 +00:00

55 lines
1.9 KiB
Java

// Sample Java file showing the fixed version of sample_java_smells.java.
// Same shape, but every smell has been resolved per the patterns documented
// in rules/universal.md and languages/java.md.
//
// Run:
// python scripts/code_quality_checker.py assets/sample_java_clean.java
//
// Expected: no HIGH Java-specific smells flagged.
package sample;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.fasterxml.jackson.databind.ObjectMapper;
public class UserService {
// FIX: heavy object shared as a singleton instead of constructed per call.
private static final ObjectMapper MAPPER = new ObjectMapper();
// FIX: connection string injected from configuration, never inlined.
private final String connectionString;
public UserService(String connectionString) {
this.connectionString = connectionString;
}
public String getName(Connection conn, int id) {
// FIX: try-with-resources guarantees the stream and statement close.
try (InputStream config = new FileInputStream("/etc/config");
// FIX: parameterized query, no string concatenation.
PreparedStatement stmt =
conn.prepareStatement("SELECT name FROM users WHERE id = ?")) {
stmt.setInt(1, id);
try (ResultSet rs = stmt.executeQuery()) {
return rs.next() ? rs.getString("name") : null;
}
} catch (Exception e) {
// FIX: rethrow with context instead of swallowing.
throw new IllegalStateException("Failed to load user " + id, e);
}
}
public void process() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// FIX: restore the interrupt flag so cancellation still propagates.
Thread.currentThread().interrupt();
}
}
}