Skip to content

Conversation

@AleGTorres
Copy link

Hello! I ran a PMD analysis on the project and spotted a few code smells that could be cleaned up.

I've fixed 4 specific patterns to improve code consistency and performance:

  • Control Statement Braces: Added missing braces to if/else blocks (e.g., in PetController.java) to prevent scope errors.
  • Guard Log Statement: Wrapped logger calls with isInfoEnabled() checks to avoid unnecessary string processing.
  • Double Brace Initialization: Replaced double-brace init with standard collection creation to avoid anonymous classes overhead.
  • Use Utility Class: Added private constructors to utility classes to prevent instantiation.

I hope these contributions are helpful to the project. Thank you!

@dsyer
Copy link
Member

dsyer commented Nov 25, 2025

I think another PR was merged that conflicts with this one. You probably need to rebase and force push.

@AleGTorres
Copy link
Author

I think another PR was merged that conflicts with this one. You probably need to rebase and force push.

Thanks for the heads up! Conflicts are resolved and the branch is up to date.

@dsyer
Copy link
Member

dsyer commented Nov 25, 2025

Github still says "This branch cannot be rebased due to conflicts". Can you rebase, squash and force push please? There's also a build failure that you should be able to see locally (just try to mvn install).

@AleGTorres
Copy link
Author

Github still says "This branch cannot be rebased due to conflicts". Can you rebase, squash and force push please? There's also a build failure that you should be able to see locally (just try to mvn install).

Done! I ran the Maven formatter to fix the build errors and squashed/rebased the commits as requested.

Fix ControlStatementBraces, GuardLogStatement, DoubleBraceInitialization and UseUtilityClass patterns.

Signed-off-by: AleGTorres <[email protected]>
static MySQLContainer container() {
return new MySQLContainer(DockerImageName.parse("mysql:9.5"));
static MySQLContainer<?> container() {
return new MySQLContainer<>(DockerImageName.parse("mysql:9.5"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: reason: cannot use '<>' with non-generic class org.testcontainers.mysql.MySQLContainer

Oops

Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the changes aren't useful IMO. The addition of missing braces is the best part of it.

@ImportRuntimeHints(PetClinicRuntimeHints.class)
public class PetClinicApplication {

private PetClinicApplication() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a false positive and need to be reverted. The application is instantiated, it's a configuration class.

@Configuration
public class MysqlTestApplication {

private MysqlTestApplication() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same this should be reverted.

public void printProperties() {
for (EnumerablePropertySource<?> source : findPropertiesPropertySources()) {
log.info("PropertySource: " + source.getName());
if (log.isInfoEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for such optimization for an info log

else {
log.info(name + "=" + value + " OVERRIDDEN to " + resolved);

if (log.isInfoEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, please revert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants