Skip to content

Commit

Permalink
improved sonar bugs and smells
Browse files Browse the repository at this point in the history
  • Loading branch information
SrdjanStevanetic committed Nov 29, 2023
1 parent 720a6c7 commit 8a13b02
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public class InvalidLanguageException extends Exception{
public InvalidLanguageException(String message) {
super(message);
}

public InvalidLanguageException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Language validateSingle(String languageAbbrevation) throws Invalid
try {
result = Language.valueOf(languageAbbrevation.trim().toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
throw new InvalidLanguageException("Language value '" + languageAbbrevation + "' is not valid");
throw new InvalidLanguageException("Language value '" + languageAbbrevation + "' is not valid", e);
}
return result;
}
Expand All @@ -62,8 +62,8 @@ public static List<Language> validateMultiple(String languageAbbrevations) throw
throw new InvalidLanguageException("Empty language value");
}

List<Language> result = new ArrayList<>();
String[] languages = languageAbbrevations.split(SEPARATOR);
List<Language> result = new ArrayList<>(languages.length);
for (String language: languages) {
result.add(validateSingle(language));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<String> detectLang(List<String> texts, String langHint) throws Langu
return Collections.emptyList();
}

List<String> detectedLangs = new ArrayList<>();
List<String> detectedLangs = new ArrayList<>(texts.size());
List<LanguageResult> tikaLanguages=null;
for(String text : texts) {
//returns all tika languages sorted by score
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public void fillWithCachedTranslations(List<TranslationObj> translationObjs) {
if (redisResponse == null || redisResponse.size() != cacheableTranslations.size()) {
// ensure that the response size corresponds to request size
// this should not happen, but better use defensive programming
int redisSize=redisResponse==null ? 0 : redisResponse.size();
logger.warn("Redis response size {} doesn't match the request size{}, for keys: {}",
redisResponse.size(), cacheableTranslations.size(), cacheKeys);
redisSize, cacheableTranslations.size(), cacheKeys);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CachedTranslationService instantiateCachedTranslationService(boolean useCaching,

private List<TranslationObj> buildTranslationObjectList(TranslationRequest translationRequest) {
// create a list of objects to be translated
List<TranslationObj> translObjs = new ArrayList<TranslationObj>();
List<TranslationObj> translObjs = new ArrayList<TranslationObj>(translationRequest.getText().size());
for (String inputText : translationRequest.getText()) {
TranslationObj newTranslObj = new TranslationObj();
newTranslObj.setSourceLang(translationRequest.getSource());
Expand Down

0 comments on commit 8a13b02

Please sign in to comment.