From f1fd29c9ad4c4deed00179d27b018eab7356cddc Mon Sep 17 00:00:00 2001 From: Antonio Castro <127856748+antoniocastro11@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:25:38 -0400 Subject: [PATCH 1/4] fix: UselessParentheses code smell (#4) Co-authored-by: Eduarda Moretto --- src/main/java/com/github/javafaker/Address.java | 4 ++-- src/main/java/com/github/javafaker/Code.java | 4 ++-- src/main/java/com/github/javafaker/Finance.java | 2 +- .../java/com/github/javafaker/idnumbers/SvSEIdNumber.java | 4 ++-- .../java/com/github/javafaker/service/FakeValuesService.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/javafaker/Address.java b/src/main/java/com/github/javafaker/Address.java index ed6b71b82..0a1653c7a 100644 --- a/src/main/java/com/github/javafaker/Address.java +++ b/src/main/java/com/github/javafaker/Address.java @@ -88,11 +88,11 @@ public String lastName() { } public String latitude() { - return String.format("%.8g", (faker.random().nextDouble() * 180) - 90); + return String.format("%.8g", faker.random().nextDouble() * 180 - 90); } public String longitude() { - return String.format("%.8g", (faker.random().nextDouble() * 360) - 180); + return String.format("%.8g", faker.random().nextDouble() * 360 - 180); } public String timeZone() { diff --git a/src/main/java/com/github/javafaker/Code.java b/src/main/java/com/github/javafaker/Code.java index e92517fa2..448584bb3 100644 --- a/src/main/java/com/github/javafaker/Code.java +++ b/src/main/java/com/github/javafaker/Code.java @@ -122,7 +122,7 @@ private final int isbn10CheckDigit(CharSequence t) { String value = stripIsbnSeparator(t); int sum = 0; for (int i = 0; i < value.length(); i++) { - sum += ((i + 1) * toInt(value.substring(i, i + 1))); + sum += (i + 1) * toInt(value.substring(i, i + 1)); } return sum % 11; } @@ -180,7 +180,7 @@ public String imei() { } // Choose the last digit so that it causes the entire string to pass the checksum. - str[len - 1] = Character.forDigit(((10 - (sum % 10)) % 10), 10); + str[len - 1] = Character.forDigit((10 - (sum % 10)) % 10, 10); return new String(str); } diff --git a/src/main/java/com/github/javafaker/Finance.java b/src/main/java/com/github/javafaker/Finance.java index c4eeddf54..0f4114a76 100644 --- a/src/main/java/com/github/javafaker/Finance.java +++ b/src/main/java/com/github/javafaker/Finance.java @@ -35,7 +35,7 @@ public String creditCard(CreditCardType creditCardType) { int luhnSum = 0; int multiplier = 1; for (Integer digit : reversedAsInt) { - multiplier = (multiplier == 2 ? 1 : 2); + multiplier = multiplier == 2 ? 1 : 2; luhnSum += sum(String.valueOf(digit * multiplier).split("")); } int luhnDigit = (10 - (luhnSum % 10)) % 10; diff --git a/src/main/java/com/github/javafaker/idnumbers/SvSEIdNumber.java b/src/main/java/com/github/javafaker/idnumbers/SvSEIdNumber.java index 8bd0d1949..5b22735b0 100644 --- a/src/main/java/com/github/javafaker/idnumbers/SvSEIdNumber.java +++ b/src/main/java/com/github/javafaker/idnumbers/SvSEIdNumber.java @@ -74,10 +74,10 @@ private int calculateChecksum(String number) { String calculatedNumber = calculateDigits(dateString + birthNumber); int sum = calculateDigitSum(calculatedNumber); - int lastDigit = (sum % 10); + int lastDigit = sum % 10; int difference = 10 - lastDigit; - return (difference % 10); + return difference % 10; } private String calculateDigits(String numbers) { diff --git a/src/main/java/com/github/javafaker/service/FakeValuesService.java b/src/main/java/com/github/javafaker/service/FakeValuesService.java index 13a75b046..39008dc00 100644 --- a/src/main/java/com/github/javafaker/service/FakeValuesService.java +++ b/src/main/java/com/github/javafaker/service/FakeValuesService.java @@ -278,7 +278,7 @@ public String letterify(String letterString) { * @return */ public String letterify(String letterString, boolean isUpper) { - return letterHelper((isUpper) ? 65 : 97, letterString); // from ascii table + return letterHelper(isUpper ? 65 : 97, letterString); // from ascii table } private String letterHelper(int baseChar, String letterString) { From b04cb97693c371f00bfce8c3330c4a491f275b5f Mon Sep 17 00:00:00 2001 From: Antonio Castro <127856748+antoniocastro11@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:25:54 -0400 Subject: [PATCH 2/4] fix: solving use locale with case conversions code smell (#3) * fix: ControlStatementBraces code smell * fix: UseLocaleWithCaseConversions code smell --- src/main/java/com/github/javafaker/Color.java | 3 ++- src/main/java/com/github/javafaker/Company.java | 3 ++- src/main/java/com/github/javafaker/File.java | 4 +++- src/main/java/com/github/javafaker/Finance.java | 5 +++-- src/main/java/com/github/javafaker/Internet.java | 9 ++++++--- src/main/java/com/github/javafaker/Name.java | 5 +++-- src/main/java/com/github/javafaker/Number.java | 8 ++++++-- .../com/github/javafaker/service/FakeValuesService.java | 7 +++++-- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/javafaker/Color.java b/src/main/java/com/github/javafaker/Color.java index ec077f494..3871ffa38 100644 --- a/src/main/java/com/github/javafaker/Color.java +++ b/src/main/java/com/github/javafaker/Color.java @@ -17,8 +17,9 @@ public String hex() { public String hex(boolean includeHashSign) { String hexString = faker.random().hex(6); - if(includeHashSign) + if(includeHashSign) { return "#" + hexString; + } return hexString; } } diff --git a/src/main/java/com/github/javafaker/Company.java b/src/main/java/com/github/javafaker/Company.java index a82bb6ca0..0fbfe81dd 100644 --- a/src/main/java/com/github/javafaker/Company.java +++ b/src/main/java/com/github/javafaker/Company.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import static org.apache.commons.lang3.StringUtils.join; @@ -79,7 +80,7 @@ public String url() { } private String domainName(){ - return StringUtils.deleteWhitespace(name().toLowerCase().replaceAll(",", "").replaceAll("'", "")); + return StringUtils.deleteWhitespace(name().toLowerCase(Locale.ROOT).replaceAll(",", "").replaceAll("'", "")); } private String domainSuffix() { diff --git a/src/main/java/com/github/javafaker/File.java b/src/main/java/com/github/javafaker/File.java index f8ab58f9f..57f56dcfd 100644 --- a/src/main/java/com/github/javafaker/File.java +++ b/src/main/java/com/github/javafaker/File.java @@ -1,5 +1,7 @@ package com.github.javafaker; +import java.util.Locale; + public class File { private final Faker faker; @@ -22,7 +24,7 @@ public String fileName() { public String fileName(String dirOrNull, String nameOrNull, String extensionOrNull, String separatorOrNull) { final String sep = separatorOrNull == null ? System.getProperty("file.separator") : separatorOrNull; final String dir = dirOrNull == null ? faker.internet().slug() : dirOrNull; - final String name = nameOrNull == null ? faker.lorem().word().toLowerCase() : nameOrNull; + final String name = nameOrNull == null ? faker.lorem().word().toLowerCase(Locale.ROOT) : nameOrNull; final String ext = extensionOrNull == null ? extension() : extensionOrNull; return dir + sep + name + "." + ext; } diff --git a/src/main/java/com/github/javafaker/Finance.java b/src/main/java/com/github/javafaker/Finance.java index 0f4114a76..9b07ab761 100644 --- a/src/main/java/com/github/javafaker/Finance.java +++ b/src/main/java/com/github/javafaker/Finance.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Locale; public class Finance { private final Faker faker; @@ -20,7 +21,7 @@ protected Finance(Faker faker) { createCountryCodeToBasicBankAccountNumberPatternMap(); public String creditCard(CreditCardType creditCardType) { - final String key = String.format("finance.credit_card.%s", creditCardType.toString().toLowerCase()); + final String key = String.format("finance.credit_card.%s", creditCardType.toString().toLowerCase(Locale.ROOT)); String value = faker.fakeValuesService().resolve(key, this, faker); final String template = faker.numerify(value); @@ -84,7 +85,7 @@ private static String calculateIbanChecksum(String countryCode, String basicBank String basis = basicBankAccountNumber + countryCode + "00"; StringBuilder sb = new StringBuilder(); - char[] characters = basis.toLowerCase().toCharArray(); + char[] characters = basis.toLowerCase(Locale.ROOT).toCharArray(); for (char c : characters) { if (Character.isLetter(c)) { sb.append(String.valueOf((c - 'a') + 10)); diff --git a/src/main/java/com/github/javafaker/Internet.java b/src/main/java/com/github/javafaker/Internet.java index 163a072e4..3d2b21202 100644 --- a/src/main/java/com/github/javafaker/Internet.java +++ b/src/main/java/com/github/javafaker/Internet.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; +import java.util.Locale; import static org.apache.commons.lang3.StringUtils.join; import static org.apache.commons.lang3.StringUtils.stripAccents; @@ -43,7 +44,7 @@ public String domainName() { } public String domainWord() { - return FakerIDN.toASCII(faker.name().lastName().toLowerCase().replaceAll("'", "")); + return FakerIDN.toASCII(faker.name().lastName().toLowerCase(Locale.ROOT).replaceAll("'", "")); } public String domainSuffix() { @@ -55,7 +56,7 @@ public String url() { "www", ".", FakerIDN.toASCII( - faker.name().firstName().toLowerCase().replaceAll("'", "") + + faker.name().firstName().toLowerCase(Locale.ROOT).replaceAll("'", "") + "-" + domainWord() ), @@ -85,7 +86,9 @@ public String avatar() { */ public String image() { String[] dimension = StringUtils.split(faker.fakeValuesService().resolve("internet.image_dimension", this, faker), 'x'); - if (dimension.length == 0) return ""; + if (dimension.length == 0) { + return ""; + } return image( Integer.valueOf(StringUtils.trim(dimension[0])), Integer.valueOf(StringUtils.trim(dimension[1])), faker.bool().bool(), null); diff --git a/src/main/java/com/github/javafaker/Name.java b/src/main/java/com/github/javafaker/Name.java index 0a5238f1d..96ef76776 100644 --- a/src/main/java/com/github/javafaker/Name.java +++ b/src/main/java/com/github/javafaker/Name.java @@ -1,6 +1,7 @@ package com.github.javafaker; import org.apache.commons.lang3.StringUtils; +import java.util.Locale; public class Name { @@ -122,9 +123,9 @@ public String title() { public String username() { String username = StringUtils.join( - firstName().replaceAll("'", "").toLowerCase(), + firstName().replaceAll("'", "").toLowerCase(Locale.ROOT), ".", - lastName().replaceAll("'", "").toLowerCase() + lastName().replaceAll("'", "").toLowerCase(Locale.ROOT) ); return StringUtils.deleteWhitespace(username); diff --git a/src/main/java/com/github/javafaker/Number.java b/src/main/java/com/github/javafaker/Number.java index 3afa93c34..27e4346f7 100644 --- a/src/main/java/com/github/javafaker/Number.java +++ b/src/main/java/com/github/javafaker/Number.java @@ -27,7 +27,9 @@ public int randomDigitNotZero() { * @see Number#numberBetween(long, long) */ public int numberBetween(int min, int max) { - if (min == max) return min; + if (min == max){ + return min;x + } int value = decimalBetween(min,max).setScale(0, BigDecimal.ROUND_HALF_DOWN).intValue(); return value == max ? value - 1 : value; @@ -42,7 +44,9 @@ public int numberBetween(int min, int max) { * @param max exclusive (unless min == max) */ public long numberBetween(long min, long max) { - if (min == max) return min; + if (min == max) { + return min; + } long value = decimalBetween(min, max).setScale(0, BigDecimal.ROUND_HALF_DOWN).longValue(); return value == max ? value - 1 : value; diff --git a/src/main/java/com/github/javafaker/service/FakeValuesService.java b/src/main/java/com/github/javafaker/service/FakeValuesService.java index 39008dc00..cb0d679fb 100644 --- a/src/main/java/com/github/javafaker/service/FakeValuesService.java +++ b/src/main/java/com/github/javafaker/service/FakeValuesService.java @@ -20,6 +20,7 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.Locale; public class FakeValuesService { @@ -157,7 +158,9 @@ public String fetchString(String key) { @SuppressWarnings("unchecked") public String safeFetch(String key, String defaultIfNull) { Object o = fetchObject(key); - if (o == null) return defaultIfNull; + if (o == null) { + return defaultIfNull; + } if (o instanceof List) { List values = (List) o; if (values.size() == 0) { @@ -456,7 +459,7 @@ private String classNameToYamlName(Object current) { private String javaNameToYamlName(String expression) { return expression.replaceAll("([A-Z])", "_$1") .substring(1) - .toLowerCase(); + .toLowerCase(Locale.ROOT); } From e38caec31672bf8cb1cf498d1852908c4c6abf29 Mon Sep 17 00:00:00 2001 From: Antonio Castro <127856748+antoniocastro11@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:26:33 -0400 Subject: [PATCH 3/4] fix: solving unnecessary modifier code smell (#2) * fix: UselessParentheses code smell * fix: UnnecessaryModifier code smell --------- Co-authored-by: Eduarda Moretto --- src/main/java/com/github/javafaker/Code.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/javafaker/Code.java b/src/main/java/com/github/javafaker/Code.java index 448584bb3..de2d69ecd 100644 --- a/src/main/java/com/github/javafaker/Code.java +++ b/src/main/java/com/github/javafaker/Code.java @@ -118,16 +118,16 @@ public String isbn13(boolean separator) { return separator ? isbn13.toString() : stripIsbnSeparator(isbn13); } - private final int isbn10CheckDigit(CharSequence t) { + private int isbn10CheckDigit(CharSequence t) { String value = stripIsbnSeparator(t); int sum = 0; for (int i = 0; i < value.length(); i++) { sum += (i + 1) * toInt(value.substring(i, i + 1)); } return sum % 11; - } + } - private final int isbn13CheckDigit(CharSequence t) { + private int isbn13CheckDigit(CharSequence t) { String value = stripIsbnSeparator(t); int sum = 0; int multiplier = 0; @@ -135,12 +135,11 @@ private final int isbn13CheckDigit(CharSequence t) { multiplier = i % 2 == 0 ? 1 : 3; sum += multiplier * toInt(value.subSequence(i, i + 1).toString()); } - - return (10 - sum % 10) % 10; + return sum % 10; } - private final String stripIsbnSeparator(CharSequence t) { - return t.toString().replaceAll("-",""); + private String stripIsbnSeparator(CharSequence t) { + return t.toString().replaceAll("-", ""); } public String asin() { From 74761e516e97d5112358d728c439abe51986292a Mon Sep 17 00:00:00 2001 From: Antonio Castro <127856748+antoniocastro11@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:26:49 -0400 Subject: [PATCH 4/4] fix: ControlStatementBraces code smell (#1)