-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: resolve static analysis issues in code #13270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
cfc3361
0ff44ac
b844e0f
ff17d38
4d80b22
b6946a1
f37e553
a4e3b92
521164a
0ef1159
6681865
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,11 +194,11 @@ private Optional<Path> askForSavePath() { | |
// Workaround for linux systems not adding file extension | ||
if (!savePath.getFileName().toString().toLowerCase().endsWith(".bib")) { | ||
savePath = Path.of(savePath.toString() + ".bib"); | ||
if (!Files.notExists(savePath)) { | ||
if (!dialogService.showConfirmationDialogAndWait(Localization.lang("Overwrite file"), Localization.lang("'%0' exists. Overwrite file?", savePath.getFileName()))) { | ||
if (!Files.notExists(savePath) && !dialogService.showConfirmationDialogAndWait(Localization.lang("Overwrite file"), | ||
Localization.lang("'%0' exists. Overwrite file?", savePath.getFileName()))) { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
selectedPath = Optional.of(savePath); | ||
} | ||
} | ||
|
@@ -246,7 +246,7 @@ private boolean save(Path targetPath, SaveDatabaseMode mode) { | |
dialogService.notify(Localization.lang("Library saved")); | ||
return success; | ||
} catch (SaveException ex) { | ||
LOGGER.error("A problem occurred when trying to save the file %s".formatted(targetPath), ex); | ||
LOGGER.error("A problem occurred when trying to save the file {}", targetPath, ex); | ||
dialogService.showErrorDialogAndWait(Localization.lang("Save library"), Localization.lang("Could not save file."), ex); | ||
return false; | ||
} finally { | ||
|
@@ -307,7 +307,8 @@ private void saveWithDifferentEncoding(Path file, boolean selectedOnly, Charset | |
.filter(buttonType -> buttonType.equals(tryDifferentEncoding)) | ||
.isPresent(); | ||
if (saveWithDifferentEncoding) { | ||
Optional<Charset> newEncoding = dialogService.showChoiceDialogAndWait(Localization.lang("Save library"), Localization.lang("Select new encoding"), Localization.lang("Save library"), encoding, Encodings.getCharsets()); | ||
Optional<Charset> newEncoding = dialogService.showChoiceDialogAndWait(Localization.lang("Save library"), Localization.lang("Select new encoding"), | ||
Localization.lang("Save library"), encoding, Encodings.getCharsets()); | ||
ungerts marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+310
to
+311
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convention is to put every argument in a single line. |
||
if (newEncoding.isPresent()) { | ||
// Make sure to remember which encoding we used. | ||
libraryTab.getBibDatabaseContext().getMetaData().setEncoding(newEncoding.get(), ChangePropagation.DO_NOT_POST_EVENT); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ public class ChainedFilters implements DirectoryStream.Filter<Path> { | |
|
||
private DirectoryStream.Filter<Path>[] filters; | ||
|
||
@SafeVarargs | ||
public ChainedFilters(DirectoryStream.Filter<Path>... filters) { | ||
this.filters = filters; | ||
} | ||
Comment on lines
18
to
23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SafeVarArgs annotation is like SuppressWarnings. But ignoring warnings is imho not the best idea.
Can we use List.of on this? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.DirectoryStream.Filter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
@@ -91,7 +92,8 @@ FileNodeViewModel searchDirectory(Path directory, UnlinkedPDFFileFilter unlinked | |
// 2. GitIgnoreFilter | ||
ChainedFilters filters = new ChainedFilters(unlinkedPDFFileFilter, new GitIgnoreFileFilter(directory)); | ||
Map<Boolean, List<Path>> directoryAndFilePartition; | ||
try (Stream<Path> filesStream = StreamSupport.stream(Files.newDirectoryStream(directory, filters).spliterator(), false)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it split in two ? |
||
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory, filters); | ||
Stream<Path> filesStream = StreamSupport.stream(dirStream.spliterator(), false)) { | ||
directoryAndFilePartition = filesStream.collect(Collectors.partitioningBy(Files::isDirectory)); | ||
} catch (IOException e) { | ||
LOGGER.error("Error while searching files", e); | ||
|
@@ -136,7 +138,7 @@ FileNodeViewModel searchDirectory(Path directory, UnlinkedPDFFileFilter unlinked | |
// create and add FileNodeViewModel to the FileNodeViewModel for the current directory | ||
fileNodeViewModelForCurrentDirectory.getChildren().addAll(resultingFiles.stream() | ||
.map(FileNodeViewModel::new) | ||
.collect(Collectors.toList())); | ||
.toList()); | ||
|
||
return fileNodeViewModelForCurrentDirectory; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double negative 'notExists' makes the code harder to read and understand. Should use 'Files.exists()' instead for better readability and maintainability.