From 048e71458d2a268ce70e4ede87dd141e229eefcf Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 25 Feb 2025 22:57:23 +0100 Subject: [PATCH] Sonar: Local-Variable Type Inference should be used --- .../error/infrastructure/primary/ArgumentsReplacer.java | 2 +- .../infrastructure/primary/AssertionErrorsConfiguration.java | 2 +- .../infrastructure/primary/GeneratorErrorsConfiguration.java | 2 +- .../liquibase/main/AsyncSpringLiquibase.java.mustache | 4 ++-- .../liquibase/test/SpringLiquibaseUtilTest.java.mustache | 2 +- .../main/ApplicationErrorsConfiguration.java.mustache | 2 +- .../main/ArgumentsReplacer.java.mustache | 2 +- .../main/AssertionErrorsConfiguration.java.mustache | 2 +- .../test/ApplicationErrorsMessagesTest.java.mustache | 2 +- .../test/AssertionErrorMessagesTest.java.mustache | 2 +- .../liquibase/domain/LiquibaseModuleFactoryTest.java | 4 ++-- .../infrastructure/primary/AssertionErrorMessagesTest.java | 2 +- .../infrastructure/primary/GeneratorErrorsMessagesTest.java | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/ArgumentsReplacer.java b/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/ArgumentsReplacer.java index c34bbc5f163..50713dcaf07 100644 --- a/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/ArgumentsReplacer.java +++ b/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/ArgumentsReplacer.java @@ -22,7 +22,7 @@ public static String replaceParameters(String message, Map arguments) } private String format(String message) { - StringBuilder result = new StringBuilder(message); + var result = new StringBuilder(message); int lastMustaches = result.indexOf(OPEN); while (lastMustaches != -1) { diff --git a/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorsConfiguration.java b/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorsConfiguration.java index 42a7ecee5ad..1f524fed069 100644 --- a/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorsConfiguration.java +++ b/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorsConfiguration.java @@ -10,7 +10,7 @@ class AssertionErrorsConfiguration { @Bean("assertionErrorMessageSource") MessageSource assertionErrorMessageSource() { - ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource(); + var source = new ReloadableResourceBundleMessageSource(); source.setBasename("classpath:/messages/assertions-errors/assertion-errors-messages"); source.setDefaultEncoding("UTF-8"); diff --git a/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsConfiguration.java b/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsConfiguration.java index e1a66530afb..7bd6212ec37 100644 --- a/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsConfiguration.java +++ b/src/main/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsConfiguration.java @@ -10,7 +10,7 @@ class GeneratorErrorsConfiguration { @Bean("generatorErrorMessageSource") MessageSource generatorErrorMessageSource() { - ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource(); + var source = new ReloadableResourceBundleMessageSource(); source.setBasename("classpath:/messages/errors/generator-errors-messages"); source.setDefaultEncoding("UTF-8"); diff --git a/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/AsyncSpringLiquibase.java.mustache b/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/AsyncSpringLiquibase.java.mustache index 592782c9758..31dccbbf295 100644 --- a/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/AsyncSpringLiquibase.java.mustache +++ b/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/AsyncSpringLiquibase.java.mustache @@ -56,7 +56,7 @@ class AsyncSpringLiquibase extends DataSourceClosingSpringLiquibase { if (env.acceptsProfiles(Profiles.of("local"))) { // Prevent Thread Lock with spring-cloud-context GenericScope // https://github.com/spring-cloud/spring-cloud-commons/commit/aaa7288bae3bb4d6fdbef1041691223238d77b7b#diff-afa0715eafc2b0154475fe672dab70e4R328 - try (Connection connection = getDataSource().getConnection()) { + try (var connection = getDataSource().getConnection()) { executor.execute(() -> { try { logger.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); @@ -75,7 +75,7 @@ class AsyncSpringLiquibase extends DataSourceClosingSpringLiquibase { } protected void initDb() throws LiquibaseException { - StopWatch watch = new StopWatch(); + var watch = new StopWatch(); watch.start(); super.afterPropertiesSet(); watch.stop(); diff --git a/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache b/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache index 16533a23400..4c8fea093fb 100644 --- a/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache +++ b/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache @@ -232,7 +232,7 @@ class SpringLiquibaseUtilTest { } catch (URISyntaxException exception) { {{/yamlSpringConfigurationFormat}} {{#propertiesSpringConfigurationFormat}} - Properties properties = new Properties(); + var properties = new Properties(); properties.load( SpringLiquibaseUtilTest.class.getClassLoader().getResourceAsStream("config/application-test.properties") ); diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationErrorsConfiguration.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationErrorsConfiguration.java.mustache index 2072aaa0b6c..3fec23fc3be 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationErrorsConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationErrorsConfiguration.java.mustache @@ -10,7 +10,7 @@ class {{ baseName }}ErrorsConfiguration { @Bean("applicationErrorMessageSource") MessageSource applicationErrorMessageSource() { - ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource(); + var source = new ReloadableResourceBundleMessageSource(); source.setBasename("classpath:/messages/errors/{{ baseFileName }}-errors-messages"); source.setDefaultEncoding("UTF-8"); diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ArgumentsReplacer.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ArgumentsReplacer.java.mustache index 03c51e942d2..7b24dcbcdbd 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ArgumentsReplacer.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ArgumentsReplacer.java.mustache @@ -22,7 +22,7 @@ final class ArgumentsReplacer { } private String format(String message) { - StringBuilder result = new StringBuilder(message); + var result = new StringBuilder(message); int lastMustaches = result.indexOf(OPEN); while (lastMustaches != -1) { diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsConfiguration.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsConfiguration.java.mustache index 556df06b9d1..42a5841848a 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsConfiguration.java.mustache @@ -10,7 +10,7 @@ class AssertionErrorsConfiguration { @Bean("assertionErrorMessageSource") MessageSource assertionErrorMessageSource() { - ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource(); + var source = new ReloadableResourceBundleMessageSource(); source.setBasename("classpath:/messages/assertions-errors/assertion-errors-messages"); source.setDefaultEncoding("UTF-8"); diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache index f0f0f6a1bc9..0f56142af31 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache @@ -47,7 +47,7 @@ class {{ baseName }}ErrorsMessagesTest { private static Function toProperties() { return file -> { - Properties properties = new Properties(); + var properties = new Properties(); try { properties.load(Files.newInputStream(file)); } catch (IOException e) { diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache index 67416768919..5583f56d456 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache @@ -32,7 +32,7 @@ class AssertionErrorMessagesTest { private static Function toProperties() { return file -> { - Properties properties = new Properties(); + var properties = new Properties(); try { properties.load(Files.newInputStream(file)); } catch (IOException e) { diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseModuleFactoryTest.java index ffd5a855771..298f0b391d7 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/dbmigration/liquibase/domain/LiquibaseModuleFactoryTest.java @@ -108,7 +108,7 @@ void shouldBuildModuleWithYamlSpringConfigurationFormat() { assertThatModuleWithFiles(module, pomFile(), logbackFile(), testLogbackFile()) .hasFile("src/test/java/tech/jhipster/jhlitest/wire/liquibase/infrastructure/secondary/SpringLiquibaseUtilTest.java") .containing("YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();") - .notContaining("Properties properties = new Properties();"); + .notContaining("var properties = new Properties();"); } @Test @@ -122,7 +122,7 @@ void shouldBuildModuleWithPropertiesSpringConfigurationFormat() { assertThatModuleWithFiles(module, pomFile(), logbackFile(), testLogbackFile()) .hasFile("src/test/java/tech/jhipster/jhlitest/wire/liquibase/infrastructure/secondary/SpringLiquibaseUtilTest.java") - .containing("Properties properties = new Properties();") + .containing("var properties = new Properties();") .notContaining("YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();"); } } diff --git a/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorMessagesTest.java b/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorMessagesTest.java index fb29234cb10..869cb0216d3 100644 --- a/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorMessagesTest.java +++ b/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/AssertionErrorMessagesTest.java @@ -30,7 +30,7 @@ private static Map loadMessages() { private static Function toProperties() { return file -> { - Properties properties = new Properties(); + var properties = new Properties(); try { properties.load(Files.newInputStream(file)); } catch (IOException e) { diff --git a/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsMessagesTest.java b/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsMessagesTest.java index 4944e41ca5a..59b45118fa8 100644 --- a/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsMessagesTest.java +++ b/src/test/java/tech/jhipster/lite/shared/error/infrastructure/primary/GeneratorErrorsMessagesTest.java @@ -45,7 +45,7 @@ private static Map loadMessages() { private static Function toProperties() { return file -> { - Properties properties = new Properties(); + var properties = new Properties(); try { properties.load(Files.newInputStream(file)); } catch (IOException e) {