Skip to content

Commit ee71132

Browse files
committed
Fix some trivial SonarQube issues
This commit contains the issues, which have trivial fixes and should not change the application logic itself. Permissions, IconButton and IconActionListener classes were deleted, as they were not used anywhere.
1 parent ddbe8e4 commit ee71132

File tree

70 files changed

+445
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+445
-770
lines changed

src/main/java/com/itextpdf/rups/RupsConfiguration.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -224,34 +224,20 @@ public void setOpenDuplicateFiles(boolean value) {
224224
* @param newDefaultFolder folder to use
225225
*/
226226
public void setHomeFolder(String newDefaultFolder) {
227-
final String defaultHome = System.getProperty(HOME_FOLDER_KEY);
228-
if (newDefaultFolder == null || DEFAULT_HOME_VALUE.equals(newDefaultFolder)) {
229-
newDefaultFolder = defaultHome;
230-
} else {
231-
File valueDirectory = new File(newDefaultFolder);
232-
if (!valueDirectory.exists() || !valueDirectory.isDirectory()) {
233-
newDefaultFolder = defaultHome;
234-
}
235-
}
236-
237-
this.temporaryProperties.setProperty(HOME_FOLDER_KEY, newDefaultFolder);
227+
this.temporaryProperties.setProperty(HOME_FOLDER_KEY, sanitizeHomeFolder(newDefaultFolder));
238228
}
239229

240230
public void setUserLocale(Locale locale) {
241-
if (locale == null) {
242-
locale = Locale.getDefault();
243-
}
244-
245-
this.temporaryProperties.setProperty(LOCALE_KEY, locale.toLanguageTag());
231+
this.temporaryProperties.setProperty(LOCALE_KEY, defaultIfNull(locale).toLanguageTag());
246232
}
247233

248234
/**
249235
* Saves any unsaved changes. To cancel changes, see {@link RupsConfiguration#cancelTemporaryChanges()}.
250236
*/
251237
public void saveConfiguration() {
252-
this.temporaryProperties.forEach((key, value) -> {
253-
this.systemPreferences.put((String) key, (String) value);
254-
});
238+
this.temporaryProperties.forEach((Object key, Object value) ->
239+
this.systemPreferences.put((String) key, (String) value)
240+
);
255241

256242
this.temporaryProperties.clear();
257243
}
@@ -267,9 +253,9 @@ public void cancelTemporaryChanges() {
267253
* Resets the settings in Preferences, not the local Properties object to the default.
268254
*/
269255
public void resetToDefaultProperties() {
270-
this.defaultProperties.forEach((Object key, Object value) -> {
271-
this.systemPreferences.put((String) key, (String) value);
272-
});
256+
this.defaultProperties.forEach((Object key, Object value) ->
257+
this.systemPreferences.put((String) key, (String) value)
258+
);
273259

274260
this.temporaryProperties.clear();
275261
}
@@ -297,9 +283,9 @@ public Properties getCurrentState() throws BackingStoreException {
297283
* @param properties Properties holding new values for Preferences
298284
*/
299285
public void restore(Properties properties) {
300-
properties.forEach((key, value) -> {
301-
this.systemPreferences.put((String) key, (String) value);
302-
});
286+
properties.forEach((Object key, Object value) ->
287+
this.systemPreferences.put((String) key, (String) value)
288+
);
303289
}
304290

305291
/**
@@ -312,18 +298,14 @@ public MruListHandler getMruListHandler() {
312298
}
313299

314300
private Properties loadDefaultProperties() {
315-
final InputStream resourceAsStream = RupsConfiguration.class.getResourceAsStream(DEFAULT_CONFIG_PATH);
316301
final Properties properties = new Properties();
317-
318-
if (resourceAsStream != null) {
319-
try {
302+
try (final InputStream resourceAsStream = RupsConfiguration.class.getResourceAsStream(DEFAULT_CONFIG_PATH)) {
303+
if (resourceAsStream != null) {
320304
properties.load(resourceAsStream);
321-
resourceAsStream.close();
322-
} catch (IOException e) {
323-
LoggerHelper.error(Language.ERROR_LOADING_DEFAULT_SETTINGS.getString(), e, RupsConfiguration.class);
324305
}
306+
} catch (IOException e) {
307+
LoggerHelper.error(Language.ERROR_LOADING_DEFAULT_SETTINGS.getString(), e, RupsConfiguration.class);
325308
}
326-
327309
return properties;
328310
}
329311

@@ -357,4 +339,22 @@ private String getValueFromSystemPreferences(String key, String defaultValue) {
357339
private String getValueFromSystemPreferences(String key) {
358340
return this.systemPreferences.get(key, this.defaultProperties.getProperty(key));
359341
}
342+
343+
private static Locale defaultIfNull(Locale locale) {
344+
if (locale == null) {
345+
return Locale.getDefault();
346+
}
347+
return locale;
348+
}
349+
350+
private static String sanitizeHomeFolder(String path) {
351+
if (path == null || DEFAULT_HOME_VALUE.equals(path)) {
352+
return System.getProperty(HOME_FOLDER_KEY);
353+
}
354+
final File file = new File(path);
355+
if (!file.isDirectory()) {
356+
return System.getProperty(HOME_FOLDER_KEY);
357+
}
358+
return path;
359+
}
360360
}

src/main/java/com/itextpdf/rups/RupsLauncher.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ This file is part of the iText (R) project.
5252
* iText RUPS is a tool that allows you to inspect the internal structure
5353
* of a PDF file.
5454
*/
55-
public class RupsLauncher {
55+
public final class RupsLauncher {
56+
private RupsLauncher() {
57+
// static class
58+
}
59+
5660
/**
5761
* Main method. Starts the RUPS application.
5862
*

src/main/java/com/itextpdf/rups/controller/PdfReaderController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,15 @@ public void render(PdfObjectTreeNode node) {
313313
* @param pageNumber the page number that needs to be selected
314314
*/
315315
public void gotoPage(int pageNumber) {
316-
pageNumber--;
316+
final int rowIndex = pageNumber - 1;
317317

318318
if (pages == null
319-
|| pages.getSelectedRow() == pageNumber) {
319+
|| pages.getSelectedRow() == rowIndex) {
320320
return;
321321
}
322322

323-
if (pageNumber < pages.getRowCount()) {
324-
pages.setRowSelectionInterval(pageNumber, pageNumber);
323+
if (rowIndex < pages.getRowCount()) {
324+
pages.setRowSelectionInterval(rowIndex, rowIndex);
325325
}
326326
}
327327

src/main/java/com/itextpdf/rups/controller/RupsInstanceController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ This file is part of the iText (R) project.
9696
* instance.
9797
*/
9898
public class RupsInstanceController implements TreeSelectionListener, PageSelectionListener, IRupsEventListener {
99+
private static final String PDF_FILE_SUFFIX = ".pdf";
99100

100101
private final JPanel ownerPanel;
101102

@@ -218,9 +219,8 @@ public void saveFile(File file) {
218219
OutputStream fos = null;
219220
File localFile = file;
220221
try {
221-
final String pdfSuffix = ".pdf";
222-
if (!localFile.getName().endsWith(pdfSuffix)) {
223-
localFile = new File(localFile.getPath() + pdfSuffix);
222+
if (!localFile.getName().endsWith(PDF_FILE_SUFFIX)) {
223+
localFile = new File(localFile.getPath() + PDF_FILE_SUFFIX);
224224
}
225225

226226
if (localFile.exists()) {

src/main/java/com/itextpdf/rups/io/DefaultSystemViewerAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ This file is part of the iText (R) project.
5050
import java.io.IOException;
5151

5252
public class DefaultSystemViewerAction implements ISystemViewerAction {
53+
public DefaultSystemViewerAction() {
54+
// noop
55+
}
56+
5357
@Override
5458
public final boolean isViewingSupported() {
5559
return Desktop.isDesktopSupported();

src/main/java/com/itextpdf/rups/io/TextAreaOutputStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ This file is part of the iText (R) project.
5151
/**
5252
* Everything writing to this OutputStream will be shown in a JTextArea.
5353
*/
54-
public class TextAreaOutputStream extends OutputStream {
54+
public final class TextAreaOutputStream extends OutputStream {
5555
/**
5656
* The text area to which we want to write.
5757
*/
58-
protected JTextArea text;
58+
private final JTextArea text;
5959

6060
/**
6161
* Constructs a TextAreaOutputStream.

src/main/java/com/itextpdf/rups/io/filters/PdfFilter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,17 @@ This file is part of the iText (R) project.
5353
* Filters PDF files in a {@link JFileChooser}.
5454
*/
5555
public class PdfFilter extends FileFilter {
56+
private static final String PDF_FILE_SUFFIX = ".pdf";
5657

5758
/**
5859
* A public instance of the PdfFilter.
5960
*/
6061
public static final PdfFilter INSTANCE = new PdfFilter();
6162

63+
public PdfFilter() {
64+
// noop
65+
}
66+
6267
/**
6368
* @param f File
6469
*
@@ -67,9 +72,8 @@ public class PdfFilter extends FileFilter {
6772
* @see FileFilter#accept(java.io.File)
6873
*/
6974
public boolean accept(File f) {
70-
final String suffix = ".pdf";
7175
return f != null && (f.isDirectory() || f.getName().toLowerCase(RupsConfiguration.INSTANCE.getUserLocale())
72-
.endsWith(suffix));
76+
.endsWith(PDF_FILE_SUFFIX));
7377
}
7478

7579
/**

src/main/java/com/itextpdf/rups/io/listeners/PdfTreeExpansionListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ This file is part of the iText (R) project.
5454
* Listener that checks if the expanded node has one child. If it has one child it should expand it.
5555
*/
5656
public final class PdfTreeExpansionListener implements TreeExpansionListener {
57+
public PdfTreeExpansionListener() {
58+
// noop
59+
}
5760

5861
@Override
5962
public void treeExpanded(TreeExpansionEvent event) {

src/main/java/com/itextpdf/rups/io/listeners/PdfTreeNavigationListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public class PdfTreeNavigationListener implements KeyListener, MouseListener {
5454

5555
private boolean arrowsUsedAsNavigation = false;
5656

57+
public PdfTreeNavigationListener() {
58+
// noop
59+
}
60+
5761
public boolean isLastActionKeyboardNavigation() {
5862
return arrowsUsedAsNavigation;
5963
}

src/main/java/com/itextpdf/rups/model/DialogPasswordProvider.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ public boolean isInteractive() {
9090
return true;
9191
}
9292

93-
/*
94-
* Ignoring the "Return an empty array instead of null" warning. Here null
95-
* means, that the user cancelled password input operation. So it is
96-
* different from an empty password.
97-
*/
98-
@SuppressWarnings("java:S1168")
9993
@Override
10094
public byte[] get(File originalFile) {
10195
// originalFile is ignored, since we are using a GUI
@@ -117,6 +111,7 @@ public void selectInitialValue() {
117111
final Object selectedValue = pane.getValue();
118112
// If user didn't click OK in the dialog
119113
if (!(selectedValue instanceof Integer) || (Integer) selectedValue != JOptionPane.OK_OPTION) {
114+
// null <=> password dialog was cancelled
120115
return null;
121116
}
122117
return preparePasswordForOpen(new String(passwordField.getPassword()));

0 commit comments

Comments
 (0)