You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .cursor/rules/110-java-maven-best-practices.mdc
+36-5Lines changed: 36 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
description: Maven Best Practices
3
-
globs: pom.xml
2
+
description:
3
+
globs:
4
4
alwaysApply: false
5
5
---
6
6
# Maven Best Practices
@@ -11,7 +11,34 @@ You are a Senior software engineer with extensive experience in Java software de
11
11
12
12
## Goal
13
13
14
-
Update the pom.xml based on the following rules about Maven best practices.
14
+
Analyze `pom.xml` files to identify Maven best practices improvement opportunities and present actionable alternatives to the user. When you encounter Maven POM files:
15
+
16
+
1. **Analyze** the POM for Maven best practices issues using the principles and examples below
17
+
2. **Identify** the most impactful improvements (dependency management, plugin configuration, build profiles, version management)
18
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19
+
4. **Ask** the user which improvement they'd like to implement
20
+
5. **Wait** for user choice before making any changes
21
+
22
+
**Example interaction:**
23
+
```
24
+
🔍 I found 3 Maven best practices improvements in this POM:
25
+
26
+
1. **CRITICAL: Hardcoded Dependency Versions**
27
+
- Problem: Dependencies have hardcoded versions scattered throughout the POM
28
+
- Solutions: A) Move to properties section B) Use dependencyManagement C) Import BOM files
29
+
30
+
2. **MAINTAINABILITY: Missing Plugin Version Management**
31
+
- Problem: Maven plugins lack explicit version declarations
32
+
- Solutions: A) Add pluginManagement section B) Define plugin versions in properties C) Use parent POM approach
33
+
34
+
3. **ORGANIZATION: Inconsistent POM Structure**
35
+
- Problem: Elements are not in logical order, affecting readability
36
+
- Solutions: A) Reorganize sections B) Add descriptive comments C) Use consistent naming conventions
37
+
38
+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39
+
```
40
+
41
+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
15
42
16
43
## Examples
17
44
@@ -587,8 +614,12 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
587
614
588
615
## Output Format
589
616
590
-
- Update the file pom.xml if something is not correct
617
+
- Analyze Maven POM files for best practices violations and improvement opportunities
618
+
- Present structured analysis with prioritized improvement recommendations
619
+
- Provide multiple solution options with clear pros/cons for each issue
620
+
- Wait for user selection before implementing any changes
621
+
- When implementing, apply only the chosen solution without adding unrequested plugins or dependencies
591
622
592
623
## Safeguards
593
624
594
-
- verify changes with the command: `mvn validate`
625
+
- verify changes with the command: `mvn validate` or `./mvnw validate`
Copy file name to clipboardExpand all lines: .cursor/rules/121-java-object-oriented-design.mdc
+31-2Lines changed: 31 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,33 @@ You are a Senior software engineer with extensive experience in Java software de
11
11
12
12
## Goal
13
13
14
-
Apply comprehensive guidelines for robust Java object-oriented design and refactoring. Follow core principles like SOLID, DRY, and YAGNI, implement best practices for class and interface design including favoring composition over inheritance and designing for immutability. Master encapsulation, inheritance, and polymorphism, and identify and refactor common object-oriented design code smells such as God Classes, Feature Envy, and Data Clumps to promote maintainable, flexible, and understandable code.
14
+
Analyze Java code to identify object-oriented design improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
15
+
16
+
1. **Analyze** the code for OOD issues using the principles and examples below
17
+
2. **Identify** the most impactful improvements (SOLID violations, code smells, design patterns)
18
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19
+
4. **Ask** the user which improvement they'd like to implement
20
+
5. **Wait** for user choice before making any changes
21
+
22
+
**Example interaction:**
23
+
```
24
+
🔍 I found 3 object-oriented design improvements in this code:
25
+
26
+
1. **CRITICAL: Single Responsibility Principle Violation**
27
+
- Problem: UserService handles data, persistence, and notifications
28
+
- Solutions: A) Split into separate services B) Extract repositories C) Use mediator pattern
29
+
30
+
2. **DESIGN: Feature Envy in calculateTotal()**
31
+
- Problem: Method uses more Order data than Item data
32
+
- Solutions: A) Move to Order class B) Create Calculator utility C) Use visitor pattern
33
+
34
+
3. **QUALITY: Public fields break encapsulation**
35
+
- Solutions: A) Add getters/setters B) Use records C) Apply builder pattern
36
+
37
+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
38
+
```
39
+
40
+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
15
41
16
42
### Implementing These Principles
17
43
@@ -2471,4 +2497,7 @@ public class FileManager {
2471
2497
2472
2498
- Apply object-oriented design principles to improve code quality and maintainability
2473
2499
- Refactor code to follow SOLID principles and eliminate design smells
2474
-
- Verify code changes compile and pass tests
2500
+
2501
+
## Safeguards
2502
+
2503
+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`
Copy file name to clipboardExpand all lines: .cursor/rules/122-java-type-design.mdc
+34-2Lines changed: 34 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,36 @@ You are a Senior software engineer with extensive experience in Java software de
13
13
14
14
Type design thinking in Java applies typography principles to code structure and organization. Just as typography creates readable, accessible text, thoughtful type design in Java produces maintainable, comprehensible code.
15
15
16
-
### Implementing These Principles
16
+
Analyze Java code to identify type design improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
17
+
18
+
1. **Analyze** the code for type design issues using the principles and examples below
19
+
2. **Identify** the most impactful improvements (primitive obsession, type hierarchy problems, naming inconsistencies, missing type safety)
20
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
21
+
4. **Ask** the user which improvement they'd like to implement
22
+
5. **Wait** for user choice before making any changes
23
+
24
+
**Example interaction:**
25
+
```
26
+
🔍 I found 3 type design improvements in this code:
27
+
28
+
1. **CRITICAL: Primitive Obsession with String IDs**
29
+
- Problem: Using String for CustomerID and OrderID creates type confusion
30
+
- Solutions: A) Create type-safe wrapper classes B) Use records for ID types C) Apply builder pattern with validation
31
+
32
+
2. **DESIGN: Inconsistent Naming Patterns**
33
+
- Problem: PaymentProcessor vs ShipCalc vs TaxSystem naming inconsistency
34
+
- Solutions: A) Standardize to *Service pattern B) Use *Calculator pattern C) Apply *Provider pattern
35
+
36
+
3. **SAFETY: Missing BigDecimal for Financial Calculations**
37
+
- Problem: Using double for monetary calculations causes precision issues
38
+
- Solutions: A) Convert to BigDecimal with rounding B) Create Money type wrapper C) Use financial calculation utilities
39
+
40
+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
41
+
```
42
+
43
+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
44
+
45
+
### Core Type Design Principles
17
46
18
47
1. **Start with domain modeling**: Sketch your type system before coding.
19
48
2. **Create a type style guide**: Document naming conventions and patterns.
@@ -859,4 +888,7 @@ class BadProductService {
859
888
- Use generics to create flexible and reusable components
860
889
- Establish clear type hierarchies and consistent naming conventions
861
890
- Use BigDecimal for precision-sensitive calculations
862
-
- Verify code changes compile and pass tests
891
+
892
+
## Safeguards
893
+
894
+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`
Copy file name to clipboardExpand all lines: .cursor/rules/123-java-general-guidelines.mdc
+36-1Lines changed: 36 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,38 @@ You are a Senior software engineer with extensive experience in Java software de
11
11
12
12
## Goal
13
13
14
-
This document outlines general Java coding guidelines covering fundamental aspects such as naming conventions for packages, classes, methods, variables, and constants; code formatting rules including indentation, line length, brace style, and whitespace usage; standards for organizing import statements; best practices for Javadoc documentation; and comprehensive error and exception handling with a strong focus on security, including avoiding sensitive information exposure, catching specific exceptions, and secure resource management.
14
+
Analyze Java code to identify general coding guideline violations and present actionable alternatives to the user. When you encounter Java code:
15
+
16
+
1. **Analyze** the code for guideline violations using the principles and examples below
17
+
2. **Identify** the most impactful improvements (naming, formatting, imports, documentation, error handling)
18
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19
+
4. **Ask** the user which improvement they'd like to implement
20
+
5. **Wait** for user choice before making any changes
21
+
22
+
**Example interaction:**
23
+
```
24
+
🔍 I found 4 Java guideline improvements in this code:
25
+
26
+
1. **CRITICAL: Naming Convention Violations**
27
+
- Problem: Class uses snake_case, variables use Hungarian notation
28
+
- Solutions: A) Apply standard Java naming B) Refactor with IDE tools C) Gradual migration approach
Copy file name to clipboardExpand all lines: .cursor/rules/124-java-secure-coding.mdc
+32-1Lines changed: 32 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,34 @@ You are a Senior software engineer with extensive experience in Java software de
11
11
12
12
## Goal
13
13
14
-
Apply secure coding practices to Java code to prevent common vulnerabilities and enhance application security.
14
+
Analyze Java code to identify security vulnerabilities and present actionable alternatives to the user. When you encounter Java code:
15
+
16
+
1. **Analyze** the code for security issues using the principles and examples below
17
+
2. **Identify** the most critical vulnerabilities (injection flaws, weak cryptography, information disclosure, etc.)
18
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19
+
4. **Ask** the user which improvement they'd like to implement
20
+
5. **Wait** for user choice before making any changes
21
+
22
+
**Example interaction:**
23
+
```
24
+
🔒 I found 3 security vulnerabilities in this code:
25
+
26
+
1. **CRITICAL: SQL Injection Vulnerability**
27
+
- Problem: User input directly concatenated into SQL query
28
+
- Solutions: A) Use PreparedStatement B) Use JPA/Hibernate C) Add input validation layer
29
+
30
+
2. **HIGH: Weak Password Hashing**
31
+
- Problem: Using MD5 for password storage without salt
32
+
- Solutions: A) Switch to BCrypt B) Use Argon2 C) Implement PBKDF2 with salt
33
+
34
+
3. **MEDIUM: Information Disclosure in Exception Handling**
35
+
- Problem: Stack traces exposed to users
36
+
- Solutions: A) Generic error messages B) Centralized exception handler C) Separate logging
37
+
38
+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39
+
```
40
+
41
+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
15
42
16
43
This document provides essential Java secure coding guidelines, focusing on five key areas: validating all untrusted inputs to prevent attacks like injection and path traversal; protecting against injection attacks (e.g., SQL injection) by using parameterized queries or prepared statements; minimizing the attack surface by adhering to the principle of least privilege and reducing exposure; employing strong, current cryptographic algorithms for hashing, encryption, and digital signatures while avoiding deprecated ones; and handling exceptions securely by avoiding the exposure of sensitive information in error messages to users and logging detailed, non-sensitive diagnostic information for developers.
17
44
@@ -632,3 +659,7 @@ public class InsecureExceptionHandler {
632
659
}
633
660
}
634
661
```
662
+
663
+
## Safeguards
664
+
665
+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`
Copy file name to clipboardExpand all lines: .cursor/rules/125-java-concurrency.mdc
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,35 @@ You are a Senior software engineer with extensive experience in Java software de
11
11
12
12
## Goal
13
13
14
+
Analyze Java code to identify concurrency improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
15
+
16
+
1. **Analyze** the code for concurrency issues using the principles and examples below
17
+
2. **Identify** the most impactful improvements (thread safety violations, performance issues, modern alternatives)
18
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19
+
4. **Ask** the user which improvement they'd like to implement
20
+
5. **Wait** for user choice before making any changes
21
+
22
+
**Example interaction:**
23
+
```
24
+
🔍 I found 3 concurrency improvements in this code:
25
+
26
+
1. **CRITICAL: Thread Safety Violation**
27
+
- Problem: HashMap accessed by multiple threads without synchronization
28
+
- Solutions: A) Use ConcurrentHashMap B) Add synchronization C) Use lock-free atomic operations
29
+
30
+
2. **PERFORMANCE: Blocking Operations in Virtual Threads**
31
+
- Problem: Using synchronized blocks that can pin virtual threads
32
+
- Solutions: A) Replace with ReentrantLock B) Use concurrent collections C) Redesign with async patterns
33
+
34
+
3. **MODERN: ThreadLocal with Virtual Threads**
35
+
- Problem: ThreadLocal doesn't work well with virtual threads
36
+
- Solutions: A) Use ScopedValue B) Pass context explicitly C) Use structured concurrency
37
+
38
+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39
+
```
40
+
41
+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
42
+
14
43
Effective Java concurrency relies on understanding thread safety fundamentals, using `java.util.concurrent` utilities, and managing thread pools with `ExecutorService`. Key practices include implementing concurrent design patterns like Producer-Consumer, leveraging `CompletableFuture` for asynchronous tasks, and ensuring thread safety through immutability and safe publication. Performance aspects like lock contention and memory consistency must be considered. Thorough testing, including stress tests and thread dump analysis, is crucial. Modern Java offers virtual threads for enhanced scalability, structured concurrency for simplified task management, and scoped values for safer thread-shared data as alternatives to thread-locals.
15
44
16
45
### Implementing These Principles
@@ -1651,3 +1680,7 @@ class BadScopedValueUsage {
1651
1680
}
1652
1681
}
1653
1682
```
1683
+
1684
+
## Safeguards
1685
+
1686
+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`
Copy file name to clipboardExpand all lines: .cursor/rules/126-java-logging.mdc
+32-1Lines changed: 32 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,34 @@ You are a Senior software engineer with extensive experience in Java software de
11
11
12
12
## Goal
13
13
14
-
Effective Java logging involves selecting a standard framework (SLF4J with Logback/Log4j2), using appropriate log levels (ERROR, WARN, INFO, DEBUG, TRACE), and adhering to core practices like parameterized logging, proper exception handling, and avoiding sensitive data exposure. Configuration should be environment-specific with clear output formats. Security is paramount: mask sensitive data, control log access, and ensure secure transmission. Implement centralized log aggregation, monitoring, and alerting for proactive issue detection. Finally, logging behavior and its impact should be validated through comprehensive testing.
14
+
Analyze Java code to identify logging improvement opportunities and present actionable alternatives to the user. When you encounter Java code:
15
+
16
+
1. **Analyze** the code for logging issues using the principles and examples below
17
+
2. **Identify** the most impactful improvements (framework selection, log levels, security, performance, monitoring)
18
+
3. **Present** 2-3 concrete solution options with pros/cons for each issue found
19
+
4. **Ask** the user which improvement they'd like to implement
20
+
5. **Wait** for user choice before making any changes
21
+
22
+
**Example interaction:**
23
+
```
24
+
🔍 I found 3 logging improvements in this code:
25
+
26
+
1. **CRITICAL: Security Risk - Sensitive Data Exposure**
27
+
- Problem: Credit card numbers and passwords logged in plain text
28
+
- Solutions: A) Implement data masking B) Use structured logging with filters C) Remove sensitive logging entirely
29
+
30
+
2. **PERFORMANCE: String Concatenation in Logging**
31
+
- Problem: Using + operator instead of parameterized logging
32
+
- Solutions: A) Convert to SLF4J placeholders B) Add guard clauses C) Use lazy evaluation
33
+
34
+
3. **MAINTAINABILITY: Inconsistent Log Levels**
35
+
- Problem: Business events logged as DEBUG, errors as INFO
36
+
- Solutions: A) Standardize level usage B) Create logging guidelines C) Use different loggers by category
37
+
38
+
Which would you like to implement? (1A, 1B, 1C, 2A, 2B, 2C, 3A, 3B, 3C, or 'show more details')
39
+
```
40
+
41
+
Focus on being consultative rather than prescriptive - analyze, propose, ask, then implement based on user choice.
15
42
16
43
### Implementing These Principles
17
44
@@ -1383,3 +1410,7 @@ public class UntestableLogging {
1383
1410
}
1384
1411
}
1385
1412
```
1413
+
1414
+
## Safeguards
1415
+
1416
+
- Verify code changes compile and pass tests: `mvn clean verify` or `./mvnw clean verify`
0 commit comments