mirror of
https://github.com/alirezarezvani/claude-skills.git
synced 2026-09-07 08:26:02 +00:00
- Extract commun languages rules in a separate rules/universal.md containing all cross-language rules in one place - Move language-specific rules inline into each languages/*.md file, organised into consistent sections: Security / Async / Resource Management / Exception Handling / Performance / Idioms - Add Java support: languages/java.md with full section coverage - Every review now requires exactly 2 file reads: universal.md + one language file - Add "Adding a new language" guide to SKILL.md: one file to create, nothing else changes
4.3 KiB
4.3 KiB
| language | extensions | |
|---|---|---|
| java |
|
Java — Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only Java-specific rules and idioms.
PR Analyzer — Java Risk Signals
System.out.println/e.printStackTrace()left in production code@SuppressWarningsannotations — verify they are justified- Hardcoded JDBC URLs or credentials in source
- Raw type usage (
List,Mapwithout generics)
Code Quality — Java Checks
- Empty
catchblocks swallowing exceptions silently - Checked exceptions caught and not re-thrown with context
Closeable/AutoCloseableresources not in try-with-resources- Raw type usage — defeats generics type safety
- Missing
@Overrideon overriding methods InterruptedExceptioncaught without callingThread.currentThread().interrupt()
Security
- Flag JPQL / HQL or native SQL string concatenation — require named parameters or
CriteriaBuilder - Flag
@RequestMappingwithout explicit HTTP method restriction on state-changing endpoints - Flag user-controlled input passed to
Runtime.exec()orProcessBuilderwithout validation - Flag
ObjectInputStream.readObject()on untrusted data — unsafe deserialization - Flag hardcoded JDBC URLs or credentials — require environment variables or a vault
Async / Concurrency
- Flag
ExecutorService.submit()return value ignored — exceptions are swallowed - Flag
Thread.sleep()used as a synchronization mechanism — useCountDownLatch,CompletableFuture, orawait() - Flag
CompletableFuturechains with no.exceptionally()or.handle()terminal handler - Flag
InterruptedExceptioncaught without callingThread.currentThread().interrupt() - Flag
synchronizedon a non-final field — the lock object can be replaced - Flag
HashMapused in multi-threaded context — useConcurrentHashMap
Resource Management
- Flag
InputStream,OutputStream,Connection,ResultSet,PreparedStatementnot wrapped in try-with-resources - Flag manual
finally { resource.close() }— replace with try-with-resources - Flag
HttpURLConnectionnot disconnected after use - Flag JDBC
Connectionobtained from a pool and not returned (missingclose()) on all paths - Flag
staticHttpClientorConnectionfields shared across threads without connection pool management
Exception Handling
- Flag empty
catchblocks —catch (Exception e) {} - Flag
InterruptedExceptioncaught withoutThread.currentThread().interrupt()— breaks cooperative cancellation - Flag checked exceptions swallowed in a
catchand not re-thrown or logged with context - Flag
throw new RuntimeException(e)without a descriptive message — loses context - Flag
printStackTrace()as the sole error handling — use a proper logger
Performance
- Flag
Stringconcatenation in loops — useStringBuilder - Flag
List.contains()/Map.get()in a loop on large collections — review data structure choice - Flag N+1 JPA / Hibernate queries — use
JOIN FETCHor@BatchSize - Flag
new ObjectMapper()/new Gson()instantiated per-request — share a singleton - Flag
ResultSetfully iterated when only the first result is needed — useLIMIT 1in the query
Idioms and Best Practices
Null Safety
- Prefer returning
Optional<T>overnullfrom methods - Flag unchecked dereferences without a prior null guard
- Do not catch
NullPointerException— fix the root cause instead
Collections and Streams
- Flag
==used to compareStringor boxed types — use.equals() - Flag
.collect(Collectors.toList())where.toList()(Java 16+) suffices - Flag premature
.stream().collect()round-trips that could be a single-pass operation
Generics
- Flag raw types in any new code — always parameterize (
List<String>, notList) - Flag unchecked cast warnings suppressed without explanation
Modern Java (11+)
- Prefer
varfor local variables where the type is obvious from the right-hand side - Prefer records for pure data carriers over manual POJOs with getters/setters
- Prefer
instanceofpattern matching (if (obj instanceof String s)) over explicit casts - Prefer
switchexpressions overswitchstatements where a value is returned