Back to all reviewers

Follow consistent style conventions

spring-projects/spring-boot
Based on 8 comments
Java

Spring Boot projects maintain specific coding style conventions for consistency and readability. When contributing code, adhere to the following style guidelines:

Code Style Java

Reviewer Prompt

Spring Boot projects maintain specific coding style conventions for consistency and readability. When contributing code, adhere to the following style guidelines:

  1. Explicit type declarations: Don’t use var keyword for variable declarations. Always declare variable types explicitly: ```java // Incorrect: var sessionStore = new MaxIdleTimeInMemoryWebSessionStore(timeout);

// Correct: MaxIdleTimeInMemoryWebSessionStore sessionStore = new MaxIdleTimeInMemoryWebSessionStore(timeout);


2. **String comparison pattern**: Use "literal".equals(variable) pattern instead of Objects.equals():
```java
// Incorrect:
return Objects.equals(postgresAuthMethod, "trust");

// Correct:
return "trust".equals(postgresAuthMethod);
  1. Lambda expressions: Use parentheses around single lambda parameters: ```java // Incorrect: .map(exporter -> BatchSpanProcessor.builder(exporter).build())

// Correct: .map((exporter) -> BatchSpanProcessor.builder(exporter).build())


4. **Annotation consistency**: Explicitly declare annotations even when using default values for readability:
```java
// Keep annotations with default values for consistency
@Order(Ordered.LOWEST_PRECEDENCE)
  1. Regular expression syntax: Be consistent with character escaping in regular expressions - if you escape opening brackets, also escape closing brackets: ```java // Inconsistent: Pattern.compile(“^(.)\[(.)\]$”);

// Consistent: Pattern.compile(“^(.)\[(.)]$”); ```

  1. Ordering: Sort enum values and similar collections alphabetically for ease of finding items.

Following these conventions helps maintain a consistent codebase that’s easier to read, review, and maintain.

8
Comments Analyzed
Java
Primary Language
Code Style
Category

Source Discussions