From 8f15d33305d17156e874f7c7c83001e4b90c7834 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:18:21 +0200 Subject: [PATCH 01/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "FIRST_NAMES", "LAST_NAMES", "STREET_NAMES", "CITY_NAMES", "STATE_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "location": "FIRST_NAMES;LAST_NAMES;STREET_NAMES;CITY_NAMES;STATE_NAMES", "loc_type": "class_variable" }, "description": "The public static final arrays are mutable, which violates the immutability principle for constants. This can lead to unintended modifications by external clients. Replace these arrays with immutable collections to ensure safety and immutability.", "code_segment": "public static final String[] FIRST_NAMES = {\"John\", \"Emily\", \"Michael\", \"Sarah\", \"William\", \"Olivia\", \"James\", \"Ava\", \"Robert\", \"Isabella\"};", "suggested_fix": "Replace the mutable arrays with immutable lists using Collections.unmodifiableList and Arrays.asList. For example: public static final List FIRST_NAMES = Collections.unmodifiableList(Arrays.asList(\"John\", \"Emily\", \"Michael\", \"Sarah\", \"William\", \"Olivia\", \"James\", \"Ava\", \"Robert\", \"Isabella\"));" }, "sonarqube_issue_id": null } --- errorprone_issues.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errorprone_issues.json b/errorprone_issues.json index 565c2ca..13bb66b 100644 --- a/errorprone_issues.json +++ b/errorprone_issues.json @@ -148,5 +148,5 @@ "message": "The field 'LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); }'?" } ], - "finished_at": "2025-11-04T15:59:56+02:00" + "finished_at": "2025-11-04T19:17:40+02:00" } \ No newline at end of file From 9cee7e73e119f6060c49aad72827999a6a17f45b Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:19:37 +0200 Subject: [PATCH 02/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "FIRST_NAMES", "LAST_NAMES", "STREET_NAMES", "CITY_NAMES", "STATE_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "location": "FIRST_NAMES;LAST_NAMES;STREET_NAMES;CITY_NAMES;STATE_NAMES", "loc_type": "class_variable" }, "description": "The public static final arrays are mutable, which can lead to unintended modifications by external code. This violates the principle of immutability and can cause bugs or security issues. Replace these arrays with immutable collections to ensure they cannot be modified.", "code_segment": "public static final String[] FIRST_NAMES = {\"John\", \"Emily\", \"Michael\", \"Sarah\", \"William\", \"Olivia\", \"James\", \"Ava\", \"Robert\", \"Isabella\"};\npublic static final String[] LAST_NAMES = {\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", \"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\"};\npublic static final String[] STREET_NAMES = {\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\"};\npublic static final String[] CITY_NAMES = {\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\"};\npublic static final String[] STATE_NAMES = {\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\"};", "suggested_fix": "Replace the mutable arrays with immutable lists using `Collections.unmodifiableList`. For example:\n\n```java\npublic static final List FIRST_NAMES = Collections.unmodifiableList(Arrays.asList(\"John\", \"Emily\", \"Michael\", \"Sarah\", \"William\", \"Olivia\", \"James\", \"Ava\", \"Robert\", \"Isabella\"));\npublic static final List LAST_NAMES = Collections.unmodifiableList(Arrays.asList(\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", \"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\"));\npublic static final List STREET_NAMES = Collections.unmodifiableList(Arrays.asList(\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\"));\npublic static final List CITY_NAMES = Collections.unmodifiableList(Arrays.asList(\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\"));\npublic static final List STATE_NAMES = Collections.unmodifiableList(Arrays.asList(\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\"));\n```" }, "sonarqube_issue_id": null } --- errorprone_issues.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errorprone_issues.json b/errorprone_issues.json index 13bb66b..d06a377 100644 --- a/errorprone_issues.json +++ b/errorprone_issues.json @@ -148,5 +148,5 @@ "message": "The field 'LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); }'?" } ], - "finished_at": "2025-11-04T19:17:40+02:00" + "finished_at": "2025-11-04T19:19:01+02:00" } \ No newline at end of file From 9a05c74e2110f3032cdcce260648e57d34a05515 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:20:31 +0200 Subject: [PATCH 03/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "STREET_NAMES", "CITY_NAMES", "STATE_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "loc_type": "class_variable", "location": "STREET_NAMES;CITY_NAMES;STATE_NAMES" }, "description": "The public static final arrays STREET_NAMES, CITY_NAMES, and STATE_NAMES are mutable, which can lead to unintended modifications by external code. This violates the principle of immutability for constants.", "code_segment": "public static final String[] STREET_NAMES = {\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\"};\npublic static final String[] CITY_NAMES = {\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\"};\npublic static final String[] STATE_NAMES = {\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\"};", "suggested_fix": "Replace the mutable arrays with immutable lists using Collections.unmodifiableList and Arrays.asList. For example:\n\npublic static final List STREET_NAMES = Collections.unmodifiableList(Arrays.asList(\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\"));\npublic static final List CITY_NAMES = Collections.unmodifiableList(Arrays.asList(\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\"));\npublic static final List STATE_NAMES = Collections.unmodifiableList(Arrays.asList(\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\"));" }, "sonarqube_issue_id": null } --- errorprone_issues.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errorprone_issues.json b/errorprone_issues.json index d06a377..5d75a9b 100644 --- a/errorprone_issues.json +++ b/errorprone_issues.json @@ -148,5 +148,5 @@ "message": "The field 'LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); }'?" } ], - "finished_at": "2025-11-04T19:19:01+02:00" + "finished_at": "2025-11-04T19:19:57+02:00" } \ No newline at end of file From 73f1fec803013afe05b6ddb57fb4ab8ed27eea48 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:36:18 +0200 Subject: [PATCH 04/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "FIRST_NAMES", "LAST_NAMES", "STREET_NAMES", "CITY_NAMES", "STATE_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "location": "FIRST_NAMES;LAST_NAMES;STREET_NAMES;CITY_NAMES;STATE_NAMES", "loc_type": "class_variable" }, "description": "The public static final arrays are mutable, which can lead to unintended modifications by external clients. This violates encapsulation and can cause unpredictable behavior. To address this, replace the arrays with immutable lists.", "code_segment": "public static final String[] FIRST_NAMES = {\"John\", \"Emily\", \"Michael\", \"Sarah\", \"William\", \"Olivia\", \"James\", \"Ava\", \"Robert\", \"Isabella\"};\npublic static final String[] LAST_NAMES = {\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", \"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\"};\npublic static final String[] STREET_NAMES = {\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\"};\npublic static final String[] CITY_NAMES = {\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\"};\npublic static final String[] STATE_NAMES = {\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\"};", "suggested_fix": "Replace the mutable arrays with immutable lists using `Collections.unmodifiableList`. For example:\n\n```java\npublic static final List FIRST_NAMES = Collections.unmodifiableList(Arrays.asList(\"John\", \"Emily\", \"Michael\", \"Sarah\", \"William\", \"Olivia\", \"James\", \"Ava\", \"Robert\", \"Isabella\"));\npublic static final List LAST_NAMES = Collections.unmodifiableList(Arrays.asList(\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", \"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\"));\npublic static final List STREET_NAMES = Collections.unmodifiableList(Arrays.asList(\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\"));\npublic static final List CITY_NAMES = Collections.unmodifiableList(Arrays.asList(\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\"));\npublic static final List STATE_NAMES = Collections.unmodifiableList(Arrays.asList(\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\"));\n```" }, "sonarqube_issue_id": null } --- errorprone_issues.json | 2 +- .../security/CustomUserDetailsService.java | 2 +- .../security/JwtAuthenticationFilter.java | 2 +- .../modfac/service/EmployeeService.java | 20 +++++++++---------- .../example/modfac/service/UserService.java | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/errorprone_issues.json b/errorprone_issues.json index 5d75a9b..4d908d3 100644 --- a/errorprone_issues.json +++ b/errorprone_issues.json @@ -148,5 +148,5 @@ "message": "The field 'LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); }'?" } ], - "finished_at": "2025-11-04T19:19:57+02:00" + "finished_at": "2025-11-04T19:26:48+02:00" } \ No newline at end of file diff --git a/src/main/java/com/example/modfac/security/CustomUserDetailsService.java b/src/main/java/com/example/modfac/security/CustomUserDetailsService.java index 77c9f57..ad37556 100644 --- a/src/main/java/com/example/modfac/security/CustomUserDetailsService.java +++ b/src/main/java/com/example/modfac/security/CustomUserDetailsService.java @@ -32,4 +32,4 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + user.getRole())) ); } -} +} \ No newline at end of file diff --git a/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java b/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java index 9a9f21f..84ccc6a 100644 --- a/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java @@ -99,4 +99,4 @@ private String getJwtFromRequest(HttpServletRequest request) { LOGGER.debug("getJwtFromRequest method finished"); return null; } -} +} \ No newline at end of file diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index 4750f9f..e3fe5a2 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -28,11 +28,11 @@ public class EmployeeService { private final EmployeeRepository employeeRepository; - public static final String[] FIRST_NAMES = {"John", "Emily", "Michael", "Sarah", "William", "Olivia", "James", "Ava", "Robert", "Isabella"}; - public static final String[] LAST_NAMES = {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor"}; - public static final String[] STREET_NAMES = {"Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St"}; - public static final String[] CITY_NAMES = {"New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"}; - public static final String[] STATE_NAMES = {"NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA"}; + public static final List FIRST_NAMES = Collections.unmodifiableList(Arrays.asList("John", "Emily", "Michael", "Sarah", "William", "Olivia", "James", "Ava", "Robert", "Isabella")); + public static final List LAST_NAMES = Collections.unmodifiableList(Arrays.asList("Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor")); + public static final List STREET_NAMES = Collections.unmodifiableList(Arrays.asList("Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St")); + public static final List CITY_NAMES = Collections.unmodifiableList(Arrays.asList("New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose")); + public static final List STATE_NAMES = Collections.unmodifiableList(Arrays.asList("NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA")); /** * An immutable list of country names that can be safely used without concerns about mutability. */ @@ -128,8 +128,8 @@ public Map generateEmployees(int numEmployees) { Employee employee = new Employee(); // Random name - employee.setFirstName(FIRST_NAMES[random.nextInt(FIRST_NAMES.length)]); - employee.setLastName(LAST_NAMES[random.nextInt(LAST_NAMES.length)]); + employee.setFirstName(FIRST_NAMES.get(random.nextInt(FIRST_NAMES.size()))); + employee.setLastName(LAST_NAMES.get(random.nextInt(LAST_NAMES.size()))); // Random address Employee.Address address = getAddress(); @@ -174,9 +174,9 @@ private Employee setJobInfoAndReturn(Employee employee, Employee manager) { private Employee.Address getAddress() { log.debug("getAddress method invoked"); Employee.Address address = new Employee.Address(); - address.setStreet(STREET_NAMES[random.nextInt(STREET_NAMES.length)]); - address.setCity(CITY_NAMES[random.nextInt(CITY_NAMES.length)]); - address.setRegion(STATE_NAMES[random.nextInt(STATE_NAMES.length)]); + address.setStreet(STREET_NAMES.get(random.nextInt(STREET_NAMES.size()))); + address.setCity(CITY_NAMES.get(random.nextInt(CITY_NAMES.size()))); + address.setRegion(STATE_NAMES.get(random.nextInt(STATE_NAMES.size()))); address.setZipCode(ZIP_CODES.get(random.nextInt(ZIP_CODES.size()))); char blockLetter = (char) ('A' + random.nextInt(26)); address.setBlock(String.valueOf(blockLetter) + random.nextInt(20) + 1); diff --git a/src/main/java/com/example/modfac/service/UserService.java b/src/main/java/com/example/modfac/service/UserService.java index c7514f4..cef52f3 100644 --- a/src/main/java/com/example/modfac/service/UserService.java +++ b/src/main/java/com/example/modfac/service/UserService.java @@ -194,4 +194,4 @@ private void addUsersWithRole(Role role, String usernamePrefix, String passwordP LOG.debug("addUsersWithRole method finished"); } -} +} \ No newline at end of file From 7543850a7675bdf993dcb685c17fe952f5dba667 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:40:46 +0200 Subject: [PATCH 05/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "LAST_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "loc_type": "class_variable", "location": "LAST_NAMES" }, "description": "The LAST_NAMES variable is declared as a public static final List, which is immutable due to Collections.unmodifiableList. However, the ErrorProne plugin suggests that non-empty arrays are mutable and can be modified by clients of this class. To address this, ensure that the list is truly immutable and cannot be modified externally.", "code_segment": "public static final List LAST_NAMES = Collections.unmodifiableList(Arrays.asList(\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", \"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\"));", "suggested_fix": "Replace the current implementation with an ImmutableList from Google's Guava library or use a private static final List and provide a public accessor method that returns a defensive copy of the list. This ensures that the list cannot be modified externally." }, "sonarqube_issue_id": null } --- .../modfac/service/EmployeeService.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index e3fe5a2..b9cb940 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -28,16 +28,16 @@ public class EmployeeService { private final EmployeeRepository employeeRepository; - public static final List FIRST_NAMES = Collections.unmodifiableList(Arrays.asList("John", "Emily", "Michael", "Sarah", "William", "Olivia", "James", "Ava", "Robert", "Isabella")); - public static final List LAST_NAMES = Collections.unmodifiableList(Arrays.asList("Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor")); - public static final List STREET_NAMES = Collections.unmodifiableList(Arrays.asList("Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St")); - public static final List CITY_NAMES = Collections.unmodifiableList(Arrays.asList("New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose")); - public static final List STATE_NAMES = Collections.unmodifiableList(Arrays.asList("NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA")); + public static final List FIRST_NAMES = List.of("John", "Emily", "Michael", "Sarah", "William", "Olivia", "James", "Ava", "Robert", "Isabella"); + private static final List LAST_NAMES = List.of("Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor"); + public static final List STREET_NAMES = List.of("Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St"); + public static final List CITY_NAMES = List.of("New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"); + public static final List STATE_NAMES = List.of("NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA"); /** * An immutable list of country names that can be safely used without concerns about mutability. */ - public static final List COUNTRY_NAMES = Collections.unmodifiableList(Arrays.asList("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica")); - public static final List ZIP_CODES = Collections.unmodifiableList(Arrays.asList("10001", "90001", "60001", "77001", "85001", "19101", "78201", "92101", "75201", "95101")); + public static final List COUNTRY_NAMES = List.of("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica"); + public static final List ZIP_CODES = List.of("10001", "90001", "60001", "77001", "85001", "19101", "78201", "92101", "75201", "95101"); public static final int NUM_EMPLOYEES = 500; private final Random random = ThreadLocalRandom.current(); @@ -227,5 +227,9 @@ public void updateLeaveInfo(Employee employee, Map.Entry leaveEn log.debug("updateLeaveInfo method finished"); } + public List getLastNames() { + return new ArrayList<>(LAST_NAMES); + } + } \ No newline at end of file From 07e911089bcf1bc2b8d2e525c4af4a077c6c776f Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:43:46 +0200 Subject: [PATCH 06/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "STREET_NAMES", "CITY_NAMES", "STATE_NAMES", "ZIP_CODES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "loc_type": "class_variable", "location": "STREET_NAMES;CITY_NAMES;STATE_NAMES;ZIP_CODES" }, "description": "The identified lists are declared as public static final, which makes them accessible and modifiable by external classes. This violates encapsulation and can lead to unintended side effects. To address this, the lists should be made private and accessor methods should be provided to return immutable copies of the lists.", "code_segment": "public static final List STREET_NAMES = List.of(\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\");\npublic static final List CITY_NAMES = List.of(\"New York\", \"Los Angeles\", \"Chicago\", \"Houston\", \"Phoenix\", \"Philadelphia\", \"San Antonio\", \"San Diego\", \"Dallas\", \"San Jose\");\npublic static final List STATE_NAMES = List.of(\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\");\npublic static final List ZIP_CODES = List.of(\"10001\", \"90001\", \"60001\", \"77001\", \"85001\", \"19101\", \"78201\", \"92101\", \"75201\", \"95101\");", "suggested_fix": "Change the access modifier of these lists to private and provide public getter methods that return an unmodifiable view of the lists using Collections.unmodifiableList(). For example:\n\nprivate static final List STREET_NAMES = List.of(\"Main St\", \"Park Ave\", \"Elm St\", \"Oak St\", \"Maple St\", \"Pine St\", \"Cedar St\", \"Spruce St\", \"Fir St\", \"Cypress St\");\n\npublic static List getStreetNames() {\n return Collections.unmodifiableList(STREET_NAMES);\n}\n\nRepeat this pattern for CITY_NAMES, STATE_NAMES, and ZIP_CODES." }, "sonarqube_issue_id": null } --- .../modfac/service/EmployeeService.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index b9cb940..ace7dd3 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -30,14 +30,14 @@ public class EmployeeService { public static final List FIRST_NAMES = List.of("John", "Emily", "Michael", "Sarah", "William", "Olivia", "James", "Ava", "Robert", "Isabella"); private static final List LAST_NAMES = List.of("Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor"); - public static final List STREET_NAMES = List.of("Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St"); - public static final List CITY_NAMES = List.of("New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"); - public static final List STATE_NAMES = List.of("NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA"); + private static final List STREET_NAMES = List.of("Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St"); + private static final List CITY_NAMES = List.of("New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"); + private static final List STATE_NAMES = List.of("NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA"); /** * An immutable list of country names that can be safely used without concerns about mutability. */ public static final List COUNTRY_NAMES = List.of("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica"); - public static final List ZIP_CODES = List.of("10001", "90001", "60001", "77001", "85001", "19101", "78201", "92101", "75201", "95101"); + private static final List ZIP_CODES = List.of("10001", "90001", "60001", "77001", "85001", "19101", "78201", "92101", "75201", "95101"); public static final int NUM_EMPLOYEES = 500; private final Random random = ThreadLocalRandom.current(); @@ -231,5 +231,21 @@ public List getLastNames() { return new ArrayList<>(LAST_NAMES); } + public List getStreetNames() { + return Collections.unmodifiableList(STREET_NAMES); + } + + public List getCityNames() { + return Collections.unmodifiableList(CITY_NAMES); + } + + public List getStateNames() { + return Collections.unmodifiableList(STATE_NAMES); + } + + public List getZipCodes() { + return Collections.unmodifiableList(ZIP_CODES); + } + } \ No newline at end of file From 16987808998ffa72a8832e68d02d52d486a052e8 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:46:18 +0200 Subject: [PATCH 07/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "COUNTRY_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "location": "COUNTRY_NAMES", "loc_type": "class_variable" }, "description": "The COUNTRY_NAMES variable is declared as a public static final list, which is mutable. This can lead to unintended modifications by external classes. To ensure immutability, use an unmodifiable list or an immutable collection.", "code_segment": "public static final List COUNTRY_NAMES = List.of(\"France\", \"US\", \"UK\", \"Tuvalu\", \"Lesotho\", \"Kyrgyzstan\", \"Nepal\", \"Luxembourg\", \"Dominica\", \"Martinica\");", "suggested_fix": "Replace the declaration with: public static final List COUNTRY_NAMES = Collections.unmodifiableList(List.of(\"France\", \"US\", \"UK\", \"Tuvalu\", \"Lesotho\", \"Kyrgyzstan\", \"Nepal\", \"Luxembourg\", \"Dominica\", \"Martinica\")); This ensures that the list cannot be modified externally." }, "sonarqube_issue_id": null } --- src/main/java/com/example/modfac/service/EmployeeService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index ace7dd3..30b44c4 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -36,7 +36,7 @@ public class EmployeeService { /** * An immutable list of country names that can be safely used without concerns about mutability. */ - public static final List COUNTRY_NAMES = List.of("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica"); + public static final List COUNTRY_NAMES = Collections.unmodifiableList(List.of("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica")); private static final List ZIP_CODES = List.of("10001", "90001", "60001", "77001", "85001", "19101", "78201", "92101", "75201", "95101"); public static final int NUM_EMPLOYEES = 500; From 5f5feafbb5f8ac614bc942054c9375f41d3e534c Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 19:51:11 +0200 Subject: [PATCH 08/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "COUNTRY_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "loc_type": "class_variable", "location": "COUNTRY_NAMES" }, "description": "The COUNTRY_NAMES list is declared as public static final, but it is mutable. This violates the principle of immutability and can lead to unintended modifications by external classes.", "code_segment": "public static final List COUNTRY_NAMES = Collections.unmodifiableList(List.of(\"France\", \"US\", \"UK\", \"Tuvalu\", \"Lesotho\", \"Kyrgyzstan\", \"Nepal\", \"Luxembourg\", \"Dominica\", \"Martinica\"));", "suggested_fix": "Change the declaration of COUNTRY_NAMES to use an ImmutableList from Guava library or similar. For example: `public static final List COUNTRY_NAMES = ImmutableList.of(\"France\", \"US\", \"UK\", \"Tuvalu\", \"Lesotho\", \"Kyrgyzstan\", \"Nepal\", \"Luxembourg\", \"Dominica\", \"Martinica\");`. This ensures true immutability." }, "sonarqube_issue_id": null } --- .../java/com/example/modfac/service/EmployeeService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index 30b44c4..1d5295d 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -33,10 +33,10 @@ public class EmployeeService { private static final List STREET_NAMES = List.of("Main St", "Park Ave", "Elm St", "Oak St", "Maple St", "Pine St", "Cedar St", "Spruce St", "Fir St", "Cypress St"); private static final List CITY_NAMES = List.of("New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"); private static final List STATE_NAMES = List.of("NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA"); - /** - * An immutable list of country names that can be safely used without concerns about mutability. - */ - public static final List COUNTRY_NAMES = Collections.unmodifiableList(List.of("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica")); + /** + * An immutable list of country names that can be safely used without concerns about mutability. + */ + public static final List COUNTRY_NAMES = List.of("France", "US", "UK", "Tuvalu", "Lesotho", "Kyrgyzstan", "Nepal", "Luxembourg", "Dominica", "Martinica"); private static final List ZIP_CODES = List.of("10001", "90001", "60001", "77001", "85001", "19101", "78201", "92101", "75201", "95101"); public static final int NUM_EMPLOYEES = 500; From bd02ae906fd167a105198c616c893a290cd28262 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 20:07:36 +0200 Subject: [PATCH 09/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "class_variable", "object_names": [ "STATE_NAMES" ], "full_result": { "type": "MutablePublicArray", "code_location": { "loc_type": "class_variable", "location": "STATE_NAMES" }, "description": "The STATE_NAMES list is declared as private static final, but it is mutable. This violates the principle of immutability and can lead to unintended modifications within the class.", "code_segment": "private static final List STATE_NAMES = List.of(\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\");", "suggested_fix": "Change the declaration of STATE_NAMES to use an ImmutableList from Guava library or similar. For example: `private static final List STATE_NAMES = ImmutableList.of(\"NY\", \"CA\", \"IL\", \"TX\", \"AZ\", \"PA\", \"TX\", \"CA\", \"TX\", \"CA\");`. This ensures true immutability." }, "sonarqube_issue_id": null } --- .gitignore | 3 + errorprone_issues.json | 152 ------------------ .../modfac/service/EmployeeService.java | 22 --- 3 files changed, 3 insertions(+), 174 deletions(-) delete mode 100644 errorprone_issues.json diff --git a/.gitignore b/.gitignore index 0756775..9eec65d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ build/ # Logs *.log +# Errorprone issues json +errorprone_issues.json + # Temporary files *.tmp *.swp diff --git a/errorprone_issues.json b/errorprone_issues.json deleted file mode 100644 index 4d908d3..0000000 --- a/errorprone_issues.json +++ /dev/null @@ -1,152 +0,0 @@ -{ - "issues": [ - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 31, - "rule": "MutablePublicArray", - "message": "Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.\n (see https://errorprone.info/bugpattern/MutablePublicArray)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 32, - "rule": "MutablePublicArray", - "message": "Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.\n (see https://errorprone.info/bugpattern/MutablePublicArray)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 33, - "rule": "MutablePublicArray", - "message": "Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.\n (see https://errorprone.info/bugpattern/MutablePublicArray)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 34, - "rule": "MutablePublicArray", - "message": "Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.\n (see https://errorprone.info/bugpattern/MutablePublicArray)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 35, - "rule": "MutablePublicArray", - "message": "Non-empty arrays are mutable, so this `public static final` array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.\n (see https://errorprone.info/bugpattern/MutablePublicArray)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 164, - "rule": "StringCaseLocaleUsage", - "message": "Specify a `Locale` when calling `String#to{Lower,Upper}Case`. (Note: there are multiple suggested fixes; the third may be most appropriate if you're dealing with ASCII Strings.)\n (see https://errorprone.info/bugpattern/StringCaseLocaleUsage)\n Did you mean 'employee.getFirstName().toLowerCase(Locale.ROOT) + \".\" + employee.getLastName().toLowerCase() + \"@em.com\");' or 'employee.getFirstName().toLowerCase(Locale.getDefault()) + \".\" + employee.getLastName().toLowerCase() + \"@em.com\");' or 'Ascii.toLowerCase(employee.getFirstName()) + \".\" + employee.getLastName().toLowerCase() + \"@em.com\");'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 164, - "rule": "StringCaseLocaleUsage", - "message": "Specify a `Locale` when calling `String#to{Lower,Upper}Case`. (Note: there are multiple suggested fixes; the third may be most appropriate if you're dealing with ASCII Strings.)\n (see https://errorprone.info/bugpattern/StringCaseLocaleUsage)\n Did you mean 'employee.getFirstName().toLowerCase() + \".\" + employee.getLastName().toLowerCase(Locale.ROOT) + \"@em.com\");' or 'employee.getFirstName().toLowerCase() + \".\" + employee.getLastName().toLowerCase(Locale.getDefault()) + \"@em.com\");' or 'employee.getFirstName().toLowerCase() + \".\" + Ascii.toLowerCase(employee.getLastName()) + \"@em.com\");'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/EmployeeService.java", - "main_line": 165, - "rule": "JavaTimeDefaultTimeZone", - "message": "LocalDate.now() is not allowed because it silently uses the system default time-zone. You must pass an explicit time-zone (e.g., ZoneId.of(\"America/Los_Angeles\")) to this method.\n (see https://errorprone.info/bugpattern/JavaTimeDefaultTimeZone)\n Did you mean 'jobInfo.setHireDate(LocalDate.now(ZoneId.systemDefault()));'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/util/LeaveUtils.java", - "main_line": 13, - "rule": "UnusedVariable", - "message": "The field 'LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(LeaveUtils.class); }'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/util/LeaveUtils.java", - "main_line": 47, - "rule": "EnumOrdinal", - "message": "You should almost never invoke the Enum.ordinal() method or depend on the enum values by index.\n (see https://errorprone.info/bugpattern/EnumOrdinal)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/LeaveService.java", - "main_line": 63, - "rule": "NonCanonicalType", - "message": "The type `AbstractMap.SimpleEntry` was referred to by the non-canonical name `EnumMap.SimpleEntry`. This may be misleading.\n (see https://errorprone.info/bugpattern/NonCanonicalType)\n Did you mean 'return new AbstractMap.SimpleEntry<>(leave, balance - leaveDays);'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/UserService.java", - "main_line": 183, - "rule": "StringCaseLocaleUsage", - "message": "Specify a `Locale` when calling `String#to{Lower,Upper}Case`. (Note: there are multiple suggested fixes; the third may be most appropriate if you're dealing with ASCII Strings.)\n (see https://errorprone.info/bugpattern/StringCaseLocaleUsage)\n Did you mean 'LOG.info(\"Added {}/{} {}s...\", addedCount, count, role.name().toLowerCase(Locale.ROOT));' or 'LOG.info(\"Added {}/{} {}s...\", addedCount, count, role.name().toLowerCase(Locale.getDefault()));' or 'LOG.info(\"Added {}/{} {}s...\", addedCount, count, Ascii.toLowerCase(role.name()));'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/service/UserService.java", - "main_line": 192, - "rule": "StringCaseLocaleUsage", - "message": "Specify a `Locale` when calling `String#to{Lower,Upper}Case`. (Note: there are multiple suggested fixes; the third may be most appropriate if you're dealing with ASCII Strings.)\n (see https://errorprone.info/bugpattern/StringCaseLocaleUsage)\n Did you mean 'LOG.info(\"Finished adding {}s. Added: {}, Skipped (already existed): {}\", role.name().toLowerCase(Locale.ROOT), addedCount,' or 'LOG.info(\"Finished adding {}s. Added: {}, Skipped (already existed): {}\", role.name().toLowerCase(Locale.getDefault()), addedCount,' or 'LOG.info(\"Finished adding {}s. Added: {}, Skipped (already existed): {}\", Ascii.toLowerCase(role.name()), addedCount,'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/JwtTokenProvider.java", - "main_line": 43, - "rule": "JavaUtilDate", - "message": "Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.\n (see https://errorprone.info/bugpattern/JavaUtilDate)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/JwtTokenProvider.java", - "main_line": 44, - "rule": "JavaUtilDate", - "message": "Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.\n (see https://errorprone.info/bugpattern/JavaUtilDate)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/JwtTokenProvider.java", - "main_line": 44, - "rule": "JavaUtilDate", - "message": "Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.\n (see https://errorprone.info/bugpattern/JavaUtilDate)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/JwtTokenProvider.java", - "main_line": 73, - "rule": "JavaUtilDate", - "message": "Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.\n (see https://errorprone.info/bugpattern/JavaUtilDate)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/JwtTokenProvider.java", - "main_line": 73, - "rule": "JavaUtilDate", - "message": "Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.\n (see https://errorprone.info/bugpattern/JavaUtilDate)" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java", - "main_line": 51, - "rule": "StringCaseLocaleUsage", - "message": "Specify a `Locale` when calling `String#to{Lower,Upper}Case`. (Note: there are multiple suggested fixes; the third may be most appropriate if you're dealing with ASCII Strings.)\n (see https://errorprone.info/bugpattern/StringCaseLocaleUsage)\n Did you mean 'authorities.add(new SimpleGrantedAuthority(\"ROLE_\" + role.toUpperCase(Locale.ROOT)));' or 'authorities.add(new SimpleGrantedAuthority(\"ROLE_\" + role.toUpperCase(Locale.getDefault())));' or 'authorities.add(new SimpleGrantedAuthority(\"ROLE_\" + Ascii.toUpperCase(role)));'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/controller/EmployeeController.java", - "main_line": 26, - "rule": "UnusedVariable", - "message": "The field 'APPLICATION_LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(EmployeeController.class); }'?" - }, - { - "severity": "HIGH", - "file_path": "C:/Users/oleksandr.chulkin/Documents/repo/modfac/src/main/java/com/example/modfac/security/CustomUserDetailsService.java", - "main_line": 18, - "rule": "UnusedVariable", - "message": "The field 'LOGGER' is never read.\n (see https://errorprone.info/bugpattern/UnusedVariable)\n Did you mean to remove this line or 'static { org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); }'?" - } - ], - "finished_at": "2025-11-04T19:26:48+02:00" -} \ No newline at end of file diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index 1d5295d..909450a 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -226,26 +226,4 @@ public void updateLeaveInfo(Employee employee, Map.Entry leaveEn employeeRepository.save(employee); log.debug("updateLeaveInfo method finished"); } - - public List getLastNames() { - return new ArrayList<>(LAST_NAMES); - } - - public List getStreetNames() { - return Collections.unmodifiableList(STREET_NAMES); - } - - public List getCityNames() { - return Collections.unmodifiableList(CITY_NAMES); - } - - public List getStateNames() { - return Collections.unmodifiableList(STATE_NAMES); - } - - public List getZipCodes() { - return Collections.unmodifiableList(ZIP_CODES); - } - - } \ No newline at end of file From 15e3b71f8aa30fd1fd73428f181bf4c1acf5fb2e Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 20:30:30 +0200 Subject: [PATCH 10/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "method", "object_names": [ "setJobInfoAndReturn" ], "full_result": { "type": "StringCaseLocaleUsage", "code_location": { "location": "setJobInfoAndReturn", "loc_type": "method" }, "description": "The method setJobInfoAndReturn uses String#toLowerCase without specifying a Locale, which can lead to unexpected behavior in certain locales. For example, the Turkish locale treats the letter 'i' differently, which can cause issues when converting strings to lowercase. To ensure consistent behavior across all locales, specify a Locale explicitly when calling String#toLowerCase.", "code_segment": "jobInfo.setEmail(employee.getFirstName().toLowerCase() + \".\" + employee.getLastName().toLowerCase() + \"@em.com\");", "suggested_fix": "Update the code to explicitly specify a Locale when calling String#toLowerCase. For example: jobInfo.setEmail(employee.getFirstName().toLowerCase(Locale.ROOT) + \".\" + employee.getLastName().toLowerCase(Locale.ROOT) + \"@em.com\");" }, "sonarqube_issue_id": null } --- .../modfac/service/EmployeeService.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index 909450a..f1a958b 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -158,18 +158,21 @@ public Map generateEmployees(int numEmployees) { } private Employee setJobInfoAndReturn(Employee employee, Employee manager) { - log.debug("setJobInfoAndReturn method invoked"); - Employee.JobInfo jobInfo = new Employee.JobInfo(); - jobInfo.setEmail( - employee.getFirstName().toLowerCase() + "." + employee.getLastName().toLowerCase() + "@em.com"); - jobInfo.setHireDate(LocalDate.now()); - jobInfo.setJobId(String.valueOf(random.nextInt(1000))); - jobInfo.setSalary(random.nextInt(100000)); - jobInfo.setManager(manager); - employee.setJobInfo(jobInfo); - log.debug("setJobInfoAndReturn method finished"); - return employee; - } + log.debug("setJobInfoAndReturn method invoked"); + Employee.JobInfo jobInfo = new Employee.JobInfo(); + jobInfo.setEmail( + String.format("%s.%s@em.com", + employee.getFirstName().toLowerCase(Locale.ROOT), + employee.getLastName().toLowerCase(Locale.ROOT)) + ); + jobInfo.setHireDate(LocalDate.now()); + jobInfo.setJobId(String.valueOf(random.nextInt(1000))); + jobInfo.setSalary(random.nextInt(100000)); + jobInfo.setManager(manager); + employee.setJobInfo(jobInfo); + log.debug("setJobInfoAndReturn method finished"); + return employee; + } private Employee.Address getAddress() { log.debug("getAddress method invoked"); From df46be6b878148be5efc8e5cb67c056759740e67 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 23:56:06 +0200 Subject: [PATCH 11/20] refactoring-tool(src\main\java\com\example\modfac\service\EmployeeService.java): { "type": "method", "object_names": [ "setJobInfoAndReturn" ], "full_result": { "type": "error handling", "code_location": { "location": "setJobInfoAndReturn", "loc_type": "method" }, "description": "The method uses LocalDate.now() without specifying a time zone, which can lead to inconsistent behavior across different environments. This is flagged by ErrorProne as it silently uses the system default time-zone.", "code_segment": "jobInfo.setHireDate(LocalDate.now());", "suggested_fix": "Replace 'LocalDate.now()' with 'LocalDate.now(ZoneId.systemDefault())' to explicitly specify the time zone. This ensures consistent behavior regardless of the system's default time zone." }, "sonarqube_issue_id": null } --- src/main/java/com/example/modfac/service/EmployeeService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/modfac/service/EmployeeService.java b/src/main/java/com/example/modfac/service/EmployeeService.java index f1a958b..97ccd0b 100644 --- a/src/main/java/com/example/modfac/service/EmployeeService.java +++ b/src/main/java/com/example/modfac/service/EmployeeService.java @@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.time.ZoneId; import java.util.*; import java.util.concurrent.ThreadLocalRandom; @@ -165,7 +166,7 @@ private Employee setJobInfoAndReturn(Employee employee, Employee manager) { employee.getFirstName().toLowerCase(Locale.ROOT), employee.getLastName().toLowerCase(Locale.ROOT)) ); - jobInfo.setHireDate(LocalDate.now()); + jobInfo.setHireDate(LocalDate.now(ZoneId.systemDefault())); jobInfo.setJobId(String.valueOf(random.nextInt(1000))); jobInfo.setSalary(random.nextInt(100000)); jobInfo.setManager(manager); From a44b7a8c595e128829d6b24d9d8abfd61c1dc9cd Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Tue, 4 Nov 2025 23:58:24 +0200 Subject: [PATCH 12/20] refactoring-tool(src\main\java\com\example\modfac\util\LeaveUtils.java): { "type": "class_variable", "object_names": [ "LOGGER" ], "full_result": { "type": "code simplification", "code_location": { "loc_type": "class_variable", "location": "LOGGER" }, "description": "The LOGGER variable is declared but never used in the code. This is flagged by Errorprone as an unused variable. Since the LOG variable is already being used for logging, the LOGGER variable is redundant and should be removed.", "code_segment": "private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(LeaveUtils.class);", "suggested_fix": "Remove the LOGGER variable declaration from the class as it is not used anywhere in the code." }, "sonarqube_issue_id": null } --- src/main/java/com/example/modfac/util/LeaveUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/example/modfac/util/LeaveUtils.java b/src/main/java/com/example/modfac/util/LeaveUtils.java index 4e3aeb8..d7830a0 100644 --- a/src/main/java/com/example/modfac/util/LeaveUtils.java +++ b/src/main/java/com/example/modfac/util/LeaveUtils.java @@ -10,7 +10,6 @@ public final class LeaveUtils { private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(LeaveUtils.class); - private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(LeaveUtils.class); public static final int LEAVE_PERIOD_DAYS = 365; public static final LocalDate LEAVE_PERIOD_STARTING_DATE = LocalDate.of(2025, 1, 1); From 4e158f0d5f9f8dba0deca279ab070beb07163d26 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:01:44 +0200 Subject: [PATCH 13/20] refactoring-tool(src\main\java\com\example\modfac\util\LeaveUtils.java): { "type": "method", "object_names": [ "getRandomStatus" ], "full_result": { "type": "EnumOrdinal", "code_location": { "location": "getRandomStatus", "loc_type": "method" }, "description": "The use of Enum.ordinal() or depending on enum values by index is error-prone because it relies on the order of enum constants, which can change if the enum is modified. Instead, use a more robust approach to randomly select an enum value.", "code_segment": "Status result = Status.values()[RANDOM.nextInt(Status.values().length)];", "suggested_fix": "Instead of relying on the ordinal/index of the enum, use a List to store the enum values and randomly select an element from the list. This ensures that the code does not break if the order of the enum constants changes. Example: List statuses = Arrays.asList(Status.values()); Status result = statuses.get(RANDOM.nextInt(statuses.size()));" }, "sonarqube_issue_id": null } --- src/main/java/com/example/modfac/util/LeaveUtils.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/modfac/util/LeaveUtils.java b/src/main/java/com/example/modfac/util/LeaveUtils.java index d7830a0..39eb927 100644 --- a/src/main/java/com/example/modfac/util/LeaveUtils.java +++ b/src/main/java/com/example/modfac/util/LeaveUtils.java @@ -5,6 +5,7 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; +import java.util.List; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -43,11 +44,19 @@ public static LeaveType getRandomLeaveType() { public static Status getRandomStatus() { LOG.debug("getRandomStatus method invoked"); - Status result = Status.values()[RANDOM.nextInt(Status.values().length)]; + Status result = getRandomStatusUsingList(); LOG.debug("getRandomStatus method finished"); return result; } + public static Status getRandomStatusUsingList() { + LOG.debug("getRandomStatusUsingList method invoked"); + List statuses = List.of(Status.values()); + Status result = statuses.get(RANDOM.nextInt(statuses.size())); + LOG.debug("getRandomStatusUsingList method finished"); + return result; + } + private static long getRandomDays() { LOG.debug("getRandomDays method invoked"); long randomDays = (long) (RANDOM.nextDouble() * LEAVE_PERIOD_DAYS); From 7358ed1db70e48eb01b2c02aa26032fd9343351b Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:05:18 +0200 Subject: [PATCH 14/20] refactoring-tool(src\main\java\com\example\modfac\service\LeaveService.java): { "type": "method", "object_names": [ "capture" ], "full_result": { "type": "simplification", "code_location": { "location": "capture", "loc_type": "method" }, "description": "The code uses `EnumMap.SimpleEntry` which is not the canonical name for the type. This can be misleading and is flagged by Errorprone. Replace it with `AbstractMap.SimpleEntry` which is the canonical name for the type.", "code_segment": "return new EnumMap.SimpleEntry<>(leave, balance - leaveDays);", "suggested_fix": "Replace `EnumMap.SimpleEntry` with `AbstractMap.SimpleEntry` to ensure the canonical name is used. This improves code readability and avoids confusion. The corrected line should be: `return new AbstractMap.SimpleEntry<>(leave, balance - leaveDays);`." }, "sonarqube_issue_id": null } --- .../example/modfac/service/LeaveService.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/example/modfac/service/LeaveService.java b/src/main/java/com/example/modfac/service/LeaveService.java index 9c6cce5..9f87ec3 100644 --- a/src/main/java/com/example/modfac/service/LeaveService.java +++ b/src/main/java/com/example/modfac/service/LeaveService.java @@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.util.AbstractMap; import java.util.Date; import java.util.EnumMap; import java.util.Map; @@ -30,38 +31,37 @@ public class LeaveService { * Process the leave capture request with updated document structure */ public Map.Entry capture(CaptureLeaveDTO leaveDTO, Employee employee) { - log.debug("capture method invoked"); + log.debug("capture method invoked"); - LocalDate startDate = leaveDTO.getStartDate(); - LocalDate endDate = leaveDTO.getEndDate(); - int leaveDays = getLeaveDays(startDate, endDate); + LocalDate startDate = leaveDTO.getStartDate(); + LocalDate endDate = leaveDTO.getEndDate(); + int leaveDays = getLeaveDays(startDate, endDate); - LeaveType leaveType = leaveDTO.getLeaveType(); - Integer balance = employee.getLeaveInfo().get(leaveType); - if (balance == null) { - balance = 0; - } - if (balance < leaveDays) { - log.warn("Requested {} days but only {} available", leaveDays, balance); - throw new InsufficientLeaveBalanceException( - "Insufficient leave balance. Available: " + balance + - ", Requested: " + leaveDays); - } + LeaveType leaveType = leaveDTO.getLeaveType(); + Integer balance = employee.getLeaveInfo().get(leaveType); + if (balance == null) { + balance = 0; + } + if (balance < leaveDays) { + log.warn("Requested {} days but only {} available", leaveDays, balance); + throw new InsufficientLeaveBalanceException( + String.format("Insufficient leave balance. Available: %d, Requested: %d", balance, leaveDays)); + } - Employee manager = employee.getJobInfo().getManager(); - Leave leave = new Leave(); - leave.setEmployee(employee); - leave.setLeaveType(leaveType); - leave.setStartDate(startDate); - leave.setEndDate(endDate); - leave.setStatus(leaveDTO.getStatus()); - leave.setApprovedBy(manager); - leave = leaveRepository.save(leave); - log.info("Leave request processed successfully with ID: {}", leave.getId()); + Employee manager = employee.getJobInfo().getManager(); + Leave leave = new Leave(); + leave.setEmployee(employee); + leave.setLeaveType(leaveType); + leave.setStartDate(startDate); + leave.setEndDate(endDate); + leave.setStatus(leaveDTO.getStatus()); + leave.setApprovedBy(manager); + leave = leaveRepository.save(leave); + log.info("Leave request processed successfully with ID: {}", leave.getId()); - log.debug("capture method finished"); - return new EnumMap.SimpleEntry<>(leave, balance - leaveDays); - } + log.debug("capture method finished"); + return new AbstractMap.SimpleEntry<>(leave, balance - leaveDays); + } @Transactional public void generateLeave(Employee employee, Employee manager) { From a7373f013dfdb98ad32707da6b91f478508d9e23 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:09:33 +0200 Subject: [PATCH 15/20] refactoring-tool(src\main\java\com\example\modfac\service\UserService.java): { "type": "method", "object_names": [ "addUsersWithRole" ], "full_result": { "type": "error handling", "code_location": { "location": "addUsersWithRole", "loc_type": "method" }, "description": "The code does not specify a locale when calling `String#toLowerCase`. This can lead to unexpected behavior in certain locales where the case conversion rules differ. For example, the Turkish locale has different rules for upper and lower case conversion.", "code_segment": "LOG.info(\"Added {}/{} {}s...\", addedCount, count, role.name().toLowerCase());", "suggested_fix": "Specify a locale explicitly when calling `String#toLowerCase`. Use `Locale.ROOT` for a locale-independent result, or `Locale.getDefault()` if the conversion should depend on the system's default locale. For example: `role.name().toLowerCase(Locale.ROOT)`." }, "sonarqube_issue_id": null } --- src/main/java/com/example/modfac/service/UserService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/modfac/service/UserService.java b/src/main/java/com/example/modfac/service/UserService.java index cef52f3..6cbe178 100644 --- a/src/main/java/com/example/modfac/service/UserService.java +++ b/src/main/java/com/example/modfac/service/UserService.java @@ -19,6 +19,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Locale; import java.util.Optional; @Service @@ -180,7 +181,7 @@ private void addUsersWithRole(Role role, String usernamePrefix, String passwordP userRepository.save(user); addedCount++; if (addedCount % 20 == 0) { // Log progress periodically - LOG.info("Added {}/{} {}s...", addedCount, count, role.name().toLowerCase()); + LOG.info("Added {}/{} {}s...", addedCount, count, role.name().toLowerCase(Locale.ROOT)); } } catch (DuplicateKeyException e) { LOG.warn("Duplicate key error for username '{}'. Skipping.", username); @@ -189,8 +190,9 @@ private void addUsersWithRole(Role role, String usernamePrefix, String passwordP LOG.error("Error saving user '{}' with role {}: {}", username, role, e.getMessage(), e); } } - LOG.info("Finished adding {}s. Added: {}, Skipped (already existed): {}", role.name().toLowerCase(), addedCount, - skippedCount); + + LOG.info("Finished adding {}s. Added: {}, Skipped (already existed): {}", role.name().toLowerCase(Locale.ROOT), + addedCount, skippedCount); LOG.debug("addUsersWithRole method finished"); } From cd9c7a1a70012db664f8f159b83decb5a554fd5b Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:19:22 +0200 Subject: [PATCH 16/20] refactoring-tool(src\main\java\com\example\modfac\security\JwtTokenProvider.java): { "type": "method", "object_names": [ "createToken" ], "full_result": { "type": "simplification", "code_location": { "location": "createToken", "loc_type": "method" }, "description": "The createToken method uses Date for issuedAt and expiration fields, which is error-prone due to its outdated API. Replace Date with java.time.Instant for better accuracy and maintainability.", "code_segment": "Date now = new Date();\nDate validity = new Date(now.getTime() + jwtExpiration);", "suggested_fix": "Replace the usage of Date with java.time.Instant. Use Instant.now() for the current time and calculate the expiration time using Instant.plusMillis(jwtExpiration). Convert the Instant objects to java.util.Date using Date.from(instant) when setting issuedAt and expiration in the JWT builder." }, "sonarqube_issue_id": null } --- .../com/example/modfac/security/JwtTokenProvider.java | 9 +++++---- .../java/com/example/modfac/service/LeaveService.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/modfac/security/JwtTokenProvider.java b/src/main/java/com/example/modfac/security/JwtTokenProvider.java index 42541c2..e074a15 100644 --- a/src/main/java/com/example/modfac/security/JwtTokenProvider.java +++ b/src/main/java/com/example/modfac/security/JwtTokenProvider.java @@ -10,6 +10,7 @@ import javax.crypto.SecretKey; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -40,13 +41,13 @@ public String createToken(String username, String role) { claims.put("sub", username); // subject claim claims.put("role", role); // custom role claim - Date now = new Date(); - Date validity = new Date(now.getTime() + jwtExpiration); + Instant now = Instant.now(); + Instant validity = now.plusMillis(jwtExpiration); String token = Jwts.builder() .claims(claims) - .issuedAt(now) - .expiration(validity) + .issuedAt(Date.from(now)) + .expiration(Date.from(validity)) .signWith(key, Jwts.SIG.HS256) .compact(); diff --git a/src/main/java/com/example/modfac/service/LeaveService.java b/src/main/java/com/example/modfac/service/LeaveService.java index 9f87ec3..f5ec7ef 100644 --- a/src/main/java/com/example/modfac/service/LeaveService.java +++ b/src/main/java/com/example/modfac/service/LeaveService.java @@ -30,7 +30,7 @@ public class LeaveService { /** * Process the leave capture request with updated document structure */ - public Map.Entry capture(CaptureLeaveDTO leaveDTO, Employee employee) { + public Map.Entry capture(CaptureLeaveDTO leaveDTO, Employee employee) { log.debug("capture method invoked"); LocalDate startDate = leaveDTO.getStartDate(); From 818a7edeade9a02449f20f53480b76017f2e0c85 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:22:31 +0200 Subject: [PATCH 17/20] refactoring-tool(src\main\java\com\example\modfac\security\JwtTokenProvider.java): { "type": "method", "object_names": [ "validateToken" ], "full_result": { "type": "error handling", "code_location": { "location": "validateToken", "loc_type": "method" }, "description": "The validateToken method uses java.util.Date for expiration validation, which is flagged by Errorprone due to its problematic API. Replace java.util.Date with java.time.Instant for better API usage and to avoid potential bugs.", "code_segment": "boolean isValid = !claims.getPayload().getExpiration().before(new Date());", "suggested_fix": "Replace the usage of java.util.Date with java.time.Instant. Extract the expiration date as an Instant and compare it with Instant.now(). This ensures better API usage and avoids potential bugs. Example: boolean isValid = !claims.getPayload().getExpiration().toInstant().isBefore(Instant.now());" }, "sonarqube_issue_id": null } --- .../java/com/example/modfac/security/JwtTokenProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/modfac/security/JwtTokenProvider.java b/src/main/java/com/example/modfac/security/JwtTokenProvider.java index e074a15..aac82de 100644 --- a/src/main/java/com/example/modfac/security/JwtTokenProvider.java +++ b/src/main/java/com/example/modfac/security/JwtTokenProvider.java @@ -71,7 +71,9 @@ public boolean validateToken(String token) { .build() .parseSignedClaims(token); - boolean isValid = !claims.getPayload().getExpiration().before(new Date()); + Instant expiration = claims.getPayload().getExpiration().toInstant(); + boolean isValid = !expiration.isBefore(Instant.now()); + LOG.debug("validateToken method finished"); return isValid; } catch (JwtException | IllegalArgumentException e) { From 78e693f3d5450716b9ec01d2febd77e30bf0f9e5 Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:28:57 +0200 Subject: [PATCH 18/20] refactoring-tool(src\main\java\com\example\modfac\security\JwtAuthenticationFilter.java): { "type": "method", "object_names": [ "doFilterInternal" ], "full_result": { "type": "StringCaseLocaleUsage", "code_location": { "location": "doFilterInternal", "loc_type": "method" }, "description": "The issue is related to the usage of the `toUpperCase()` method without specifying a `Locale`. This can lead to unexpected behavior in certain locales where the case conversion rules differ. To ensure consistent behavior across all locales, it is recommended to specify a `Locale` explicitly when calling `toUpperCase()`.", "code_segment": "authorities.add(new SimpleGrantedAuthority(\"ROLE_\" + role.toUpperCase()));", "suggested_fix": "Replace `role.toUpperCase()` with `role.toUpperCase(Locale.ROOT)` to ensure consistent behavior across all locales. This is the most appropriate fix for ASCII strings, as it avoids locale-specific variations in case conversion." }, "sonarqube_issue_id": null } --- .../com/example/modfac/security/JwtAuthenticationFilter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java b/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java index 84ccc6a..27abb0c 100644 --- a/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/example/modfac/security/JwtAuthenticationFilter.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Locale; @Component @RequiredArgsConstructor @@ -48,7 +49,7 @@ protected void doFilterInternal( List authorities = new ArrayList<>(); if (StringUtils.hasText(role)) { - authorities.add(new SimpleGrantedAuthority("ROLE_" + role.toUpperCase())); + authorities.add(new SimpleGrantedAuthority(String.format("ROLE_%s", role.toUpperCase(Locale.ROOT)))); } UserDetails userDetails = userDetailsService.loadUserByUsername(username); @@ -59,8 +60,6 @@ protected void doFilterInternal( authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); } else { - // If we reach here, it means the JWT token is invalid or missing - // So we set the WWW-Authenticate header and throw a 401 response response.setHeader("WWW-Authenticate", "Bearer"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; From b03a66657b63317dc386e856af86a905e8cd093f Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:31:26 +0200 Subject: [PATCH 19/20] refactoring-tool(src\main\java\com\example\modfac\controller\EmployeeController.java): { "type": "class_variable", "object_names": [ "APPLICATION_LOGGER" ], "full_result": { "type": "code simplification", "code_location": { "location": "APPLICATION_LOGGER", "loc_type": "class_variable" }, "description": "The APPLICATION_LOGGER variable is declared but never used in the code. It is redundant since the LOG variable is already being used for logging. Remove the APPLICATION_LOGGER variable to simplify the code and avoid confusion.", "code_segment": "private static final org.slf4j.Logger APPLICATION_LOGGER = org.slf4j.LoggerFactory.getLogger(EmployeeController.class);", "suggested_fix": "Remove the APPLICATION_LOGGER variable declaration from the class as it is not used anywhere in the code." }, "sonarqube_issue_id": null } --- .../java/com/example/modfac/controller/EmployeeController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/modfac/controller/EmployeeController.java b/src/main/java/com/example/modfac/controller/EmployeeController.java index 30d3994..c7bfe06 100644 --- a/src/main/java/com/example/modfac/controller/EmployeeController.java +++ b/src/main/java/com/example/modfac/controller/EmployeeController.java @@ -23,8 +23,8 @@ @RequiredArgsConstructor public class EmployeeController { private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(EmployeeController.class); - private static final org.slf4j.Logger APPLICATION_LOGGER = org.slf4j.LoggerFactory.getLogger(EmployeeController.class); private final DataService dataService; + @PostMapping public ResponseEntity onboardEmployee( @Valid @RequestBody OnboardEmployeeDTO dto, From 29a2a5bd28cdea5451e89a5b34c1099c04b4616d Mon Sep 17 00:00:00 2001 From: chulkin-mdb Date: Wed, 5 Nov 2025 00:34:10 +0200 Subject: [PATCH 20/20] refactoring-tool(src\main\java\com\example\modfac\security\CustomUserDetailsService.java): { "type": "class_variable", "object_names": [ "LOGGER" ], "full_result": { "type": "code simplification", "code_location": { "location": "LOGGER", "loc_type": "class_variable" }, "description": "The LOGGER variable is declared but never used in the code. The LOG variable is used for logging instead. This creates unnecessary redundancy and confusion.", "code_segment": "private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class);", "suggested_fix": "Remove the LOGGER variable declaration as it is unused and redundant. Ensure that the LOG variable is used consistently for logging purposes." }, "sonarqube_issue_id": null } --- .../com/example/modfac/security/CustomUserDetailsService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/example/modfac/security/CustomUserDetailsService.java b/src/main/java/com/example/modfac/security/CustomUserDetailsService.java index ad37556..2baec88 100644 --- a/src/main/java/com/example/modfac/security/CustomUserDetailsService.java +++ b/src/main/java/com/example/modfac/security/CustomUserDetailsService.java @@ -15,8 +15,6 @@ @RequiredArgsConstructor public class CustomUserDetailsService implements UserDetailsService { private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); - private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(CustomUserDetailsService.class); - private final UserRepository userRepository; @Override