diff --git a/app/.classpath b/app/.classpath
index f851717ca2a..ab8079694dd 100644
--- a/app/.classpath
+++ b/app/.classpath
@@ -4,7 +4,6 @@
-
@@ -53,4 +52,5 @@
+
diff --git a/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java b/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java
index d28d735e35f..ba048503c6b 100644
--- a/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java
+++ b/app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java
@@ -29,6 +29,7 @@
package cc.arduino.contributions;
+import cc.arduino.contributions.packages.ContributedPackage;
import cc.arduino.contributions.packages.ContributedPlatform;
import processing.app.Base;
import processing.app.BaseNoGui;
@@ -36,6 +37,7 @@
import processing.app.PreferencesData;
import javax.swing.*;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -66,14 +68,14 @@ private void builtInPackageIsNewerCheck() throws InterruptedException {
List contributedPlatforms = BaseNoGui.indexer
.getPackages().stream() //
- .map(pack -> pack.getPlatforms()) //
- .flatMap(platfs -> platfs.stream()) //
+ .map(ContributedPackage::getPlatforms) //
+ .flatMap(Collection::stream) //
.collect(Collectors.toList());
Optional mayInstalledBuiltIn = contributedPlatforms
.stream() //
- .filter(p -> p.isInstalled()) //
- .filter(p -> p.isBuiltIn()) //
+ .filter(ContributedPlatform::isInstalled) //
+ .filter(ContributedPlatform::isBuiltIn) //
.findFirst();
if (!mayInstalledBuiltIn.isPresent()) {
return;
diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryReleasesComparator.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryReleasesComparator.java
index b302306523c..6bc4ad6a438 100644
--- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryReleasesComparator.java
+++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryReleasesComparator.java
@@ -47,7 +47,7 @@ public int compare(ContributedLibraryReleases o1, ContributedLibraryReleases o2)
ContributedLibrary lib1 = o1.getLatest();
ContributedLibrary lib2 = o2.getLatest();
- if (lib1.getTypes() == null || lib2.getTypes() == null) {
+ if ((lib1.getTypes() == null) || (lib2.getTypes() == null)) {
return compareName(lib1, lib2);
}
if (lib1.getTypes().contains(firstType) && lib2.getTypes().contains(firstType)) {
diff --git a/app/src/cc/arduino/contributions/libraries/ui/DropdownInstalledLibraryItem.java b/app/src/cc/arduino/contributions/libraries/ui/DropdownInstalledLibraryItem.java
index e5b42e3b37a..bb285aa0cd0 100644
--- a/app/src/cc/arduino/contributions/libraries/ui/DropdownInstalledLibraryItem.java
+++ b/app/src/cc/arduino/contributions/libraries/ui/DropdownInstalledLibraryItem.java
@@ -44,12 +44,7 @@ public String toString() {
@Override
public Predicate getFilterPredicate() {
- return new Predicate() {
- @Override
- public boolean test(ContributedLibraryReleases t) {
- return t.getInstalled().isPresent();
- }
- };
+ return t -> t.getInstalled().isPresent();
}
}
diff --git a/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfCategoryItem.java b/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfCategoryItem.java
index 0d07b3ccf03..464c432a7d4 100644
--- a/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfCategoryItem.java
+++ b/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfCategoryItem.java
@@ -51,12 +51,9 @@ public String toString() {
@Override
public Predicate getFilterPredicate() {
- return new Predicate() {
- @Override
- public boolean test(ContributedLibraryReleases rel) {
- ContributedLibrary lib = rel.getLatest();
- return category.equals(lib.getCategory());
- }
+ return rel -> {
+ ContributedLibrary lib = rel.getLatest();
+ return category.equals(lib.getCategory());
};
}
diff --git a/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfTypeItem.java b/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfTypeItem.java
index 28f44a01894..b0b038f4adf 100644
--- a/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfTypeItem.java
+++ b/app/src/cc/arduino/contributions/libraries/ui/DropdownLibraryOfTypeItem.java
@@ -51,12 +51,9 @@ public String toString() {
@Override
public Predicate getFilterPredicate() {
- return new Predicate() {
- @Override
- public boolean test(ContributedLibraryReleases lib) {
- List types = lib.getLatest().getTypes();
- return types != null && types.contains(type);
- }
+ return lib -> {
+ List types = lib.getLatest().getTypes();
+ return types != null && types.contains(type);
};
}
diff --git a/app/src/cc/arduino/contributions/libraries/ui/DropdownUpdatableLibrariesItem.java b/app/src/cc/arduino/contributions/libraries/ui/DropdownUpdatableLibrariesItem.java
index 2c75498f822..bde8d764b7b 100644
--- a/app/src/cc/arduino/contributions/libraries/ui/DropdownUpdatableLibrariesItem.java
+++ b/app/src/cc/arduino/contributions/libraries/ui/DropdownUpdatableLibrariesItem.java
@@ -42,15 +42,9 @@ public class DropdownUpdatableLibrariesItem implements DropdownItem getFilterPredicate() {
- return new Predicate() {
- @Override
- public boolean test(ContributedLibraryReleases lib) {
- Optional mayInstalled = lib.getInstalled();
- if (!mayInstalled.isPresent()) {
- return false;
- }
- return !lib.getLatest().equals(mayInstalled.get());
- }
+ return lib -> {
+ Optional mayInstalled = lib.getInstalled();
+ return mayInstalled.filter(contributedLibrary -> !lib.getLatest().equals(contributedLibrary)).isPresent();
};
}
diff --git a/app/src/cc/arduino/contributions/packages/filters/UpdatablePlatformPredicate.java b/app/src/cc/arduino/contributions/packages/filters/UpdatablePlatformPredicate.java
index 019b5118eee..b36381bb330 100644
--- a/app/src/cc/arduino/contributions/packages/filters/UpdatablePlatformPredicate.java
+++ b/app/src/cc/arduino/contributions/packages/filters/UpdatablePlatformPredicate.java
@@ -49,8 +49,6 @@ public boolean test(ContributedPlatform contributedPlatform) {
}
List platforms = BaseNoGui.indexer.getIndex().findPlatforms(packageName, architecture);
- return platforms.stream()
- .filter(platform -> VersionComparator.greaterThan(platform.getParsedVersion(), installed.getParsedVersion()))
- .count() > 0;
+ return platforms.stream().anyMatch(platform -> VersionComparator.greaterThan(platform.getParsedVersion(), installed.getParsedVersion()));
}
}
diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java
index 3545b1ff42b..36523445f18 100644
--- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java
+++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java
@@ -70,9 +70,9 @@ public void add(ContributedPlatform platform) {
public ContributedPlatform getInstalled() {
List installedReleases = releases.stream()
- .filter(p -> p.isInstalled()) //
+ .filter(ContributedPlatform::isInstalled) //
.collect(Collectors.toList());
- Collections.sort(installedReleases, ContributedPlatform.BUILTIN_AS_LAST);
+ installedReleases.sort(ContributedPlatform.BUILTIN_AS_LAST);
if (installedReleases.isEmpty()) {
return null;
@@ -97,4 +97,4 @@ public void select(ContributedPlatform value) {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java
index 26bcb1c9d3b..b6f1376d2b1 100644
--- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java
+++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java
@@ -89,8 +89,8 @@ public Component getTableCellEditorComponent(JTable table, Object _value,
.collect(Collectors.toList());
List installedBuiltIn = releases.stream() //
- .filter(p -> p.isInstalled()) //
- .filter(p -> p.isBuiltIn()) //
+ .filter(ContributedPlatform::isInstalled) //
+ .filter(ContributedPlatform::isBuiltIn) //
.collect(Collectors.toList());
if (installed != null && !installedBuiltIn.contains(installed)) {
diff --git a/app/src/cc/arduino/contributions/ui/FilteredAbstractTableModel.java b/app/src/cc/arduino/contributions/ui/FilteredAbstractTableModel.java
index 348561c31bf..dbe8e0c5d06 100644
--- a/app/src/cc/arduino/contributions/ui/FilteredAbstractTableModel.java
+++ b/app/src/cc/arduino/contributions/ui/FilteredAbstractTableModel.java
@@ -45,7 +45,7 @@ public abstract class FilteredAbstractTableModel extends AbstractTableModel {
public static T getLatestOf(List contribs) {
contribs = new LinkedList<>(contribs);
final VersionComparator versionComparator = new VersionComparator();
- Collections.sort(contribs, (contrib1, contrib2) -> versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion()));
+ contribs.sort((contrib1, contrib2) -> versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion()));
if (contribs.isEmpty()) {
return null;
diff --git a/app/src/cc/arduino/view/preferences/AdditionalBoardsManagerURLTextArea.java b/app/src/cc/arduino/view/preferences/AdditionalBoardsManagerURLTextArea.java
index d5bc9cc0e52..a6d895b6a42 100644
--- a/app/src/cc/arduino/view/preferences/AdditionalBoardsManagerURLTextArea.java
+++ b/app/src/cc/arduino/view/preferences/AdditionalBoardsManagerURLTextArea.java
@@ -37,6 +37,7 @@
import java.awt.event.WindowEvent;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Objects;
import java.util.stream.Collectors;
import static processing.app.I18n.tr;
@@ -173,7 +174,7 @@ private void unofficialListURLLabelMouseClicked(java.awt.event.MouseEvent evt) {
public void setText(String text) {
Collection urls = splitAndTrim(text, ",");
- additionalBoardsManagerURLs.setText(urls.stream().filter(s -> s != null).collect(Collectors.joining("\n")));
+ additionalBoardsManagerURLs.setText(urls.stream().filter(Objects::nonNull).collect(Collectors.joining("\n")));
}
private Collection splitAndTrim(String text, String separator) {
@@ -183,7 +184,7 @@ private Collection splitAndTrim(String text, String separator) {
public String getText() {
Collection urls = splitAndTrim(additionalBoardsManagerURLs.getText(), "\n");
- return urls.stream().filter(s -> s != null).collect(Collectors.joining(","));
+ return urls.stream().filter(Objects::nonNull).collect(Collectors.joining(","));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
diff --git a/app/src/processing/app/AbstractTextMonitor.java b/app/src/processing/app/AbstractTextMonitor.java
index fdfcfba760a..016e1b86030 100644
--- a/app/src/processing/app/AbstractTextMonitor.java
+++ b/app/src/processing/app/AbstractTextMonitor.java
@@ -107,11 +107,9 @@ public void windowGainedFocus(WindowEvent e) {
noLineEndingAlert.setMinimumSize(minimumSize);
lineEndings = new JComboBox(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
- lineEndings.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
- noLineEndingAlert.setForeground(pane.getBackground());
- }
+ lineEndings.addActionListener(event -> {
+ PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
+ noLineEndingAlert.setForeground(pane.getBackground());
});
if (PreferencesData.get("serial.line_ending") != null) {
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
@@ -119,11 +117,7 @@ public void actionPerformed(ActionEvent event) {
if (PreferencesData.get("serial.show_timestamp") != null) {
addTimeStampBox.setSelected(PreferencesData.getBoolean("serial.show_timestamp"));
}
- addTimeStampBox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected());
- }
- });
+ addTimeStampBox.addActionListener(e -> PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected()));
lineEndings.setMaximumSize(lineEndings.getMinimumSize());
diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
index 3cfa4c502b8..4222c3e798e 100644
--- a/app/src/processing/app/Base.java
+++ b/app/src/processing/app/Base.java
@@ -888,14 +888,11 @@ public boolean add(File file) {
recentSketchesMenuItems.clear();
for (final File recentSketch : recentSketches) {
JMenuItem recentSketchMenuItem = new JMenuItem(recentSketch.getParentFile().getName());
- recentSketchMenuItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent actionEvent) {
- try {
- handleOpen(recentSketch);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ recentSketchMenuItem.addActionListener(actionEvent -> {
+ try {
+ handleOpen(recentSketch);
+ } catch (Exception e) {
+ e.printStackTrace();
}
});
recentSketchesMenuItems.add(recentSketchMenuItem);
@@ -1012,13 +1009,11 @@ protected boolean handleQuitEach() {
public void rebuildSketchbookMenus() {
//System.out.println("async enter");
//new Exception().printStackTrace();
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- //System.out.println("starting rebuild");
- rebuildSketchbookMenu(Editor.sketchbookMenu);
- rebuildToolbarMenu(Editor.toolbarMenu);
- //System.out.println("done with rebuild");
- }
+ SwingUtilities.invokeLater(() -> {
+ //System.out.println("starting rebuild");
+ rebuildSketchbookMenu(Editor.sketchbookMenu);
+ rebuildToolbarMenu(Editor.toolbarMenu);
+ //System.out.println("done with rebuild");
});
//System.out.println("async exit");
}
@@ -1030,13 +1025,11 @@ protected void rebuildToolbarMenu(JMenu menu) {
// Add the single "Open" item
item = Editor.newJMenuItem(tr("Open..."), 'O');
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- handleOpenPrompt();
- } catch (Exception e1) {
- e1.printStackTrace();
- }
+ item.addActionListener(e -> {
+ try {
+ handleOpenPrompt();
+ } catch (Exception e1) {
+ e1.printStackTrace();
}
});
menu.add(item);
@@ -1072,6 +1065,7 @@ private LibraryList getSortedLibraries() {
return installedLibraries;
}
+ @SuppressWarnings("MagicConstant")
public void rebuildImportMenu(JMenu importMenu) {
if (importMenu == null)
return;
@@ -1087,14 +1081,12 @@ public void rebuildImportMenu(JMenu importMenu) {
importMenu.addSeparator();
JMenuItem addLibraryMenuItem = new JMenuItem(tr("Add .ZIP Library..."));
- addLibraryMenuItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Base.this.handleAddLibrary();
- BaseNoGui.librariesIndexer.rescanLibraries();
- Base.this.onBoardOrPortChange();
- Base.this.rebuildImportMenu(Editor.importMenu);
- Base.this.rebuildExamplesMenu(Editor.examplesMenu);
- }
+ addLibraryMenuItem.addActionListener(e -> {
+ Base.this.handleAddLibrary();
+ BaseNoGui.librariesIndexer.rescanLibraries();
+ Base.this.onBoardOrPortChange();
+ Base.this.rebuildImportMenu(Editor.importMenu);
+ Base.this.rebuildExamplesMenu(Editor.examplesMenu);
});
importMenu.add(addLibraryMenuItem);
importMenu.addSeparator();
@@ -1679,12 +1671,7 @@ protected boolean addSketches(JMenu menu, File folder) {
if (files == null) return false;
// Alphabetize files, since it's not always alpha order
- Arrays.sort(files, new Comparator() {
- @Override
- public int compare(File file, File file2) {
- return file.getName().compareToIgnoreCase(file2.getName());
- }
- });
+ Arrays.sort(files, (file, file2) -> file.getName().compareToIgnoreCase(file2.getName()));
boolean ifound = false;
@@ -1709,22 +1696,20 @@ private boolean addSketchesSubmenu(JMenu menu, UserLibrary lib) {
private boolean addSketchesSubmenu(JMenu menu, String name, File folder) {
- ActionListener listener = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String path = e.getActionCommand();
- File file = new File(path);
- if (file.exists()) {
- try {
- handleOpen(file);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- } else {
- showWarning(tr("Sketch Does Not Exist"),
- tr("The selected sketch no longer exists.\n"
- + "You may need to restart Arduino to update\n"
- + "the sketchbook menu."), null);
+ ActionListener listener = e -> {
+ String path = e.getActionCommand();
+ File file = new File(path);
+ if (file.exists()) {
+ try {
+ handleOpen(file);
+ } catch (Exception e1) {
+ e1.printStackTrace();
}
+ } else {
+ showWarning(tr("Sketch Does Not Exist"),
+ tr("The selected sketch no longer exists.\n"
+ + "You may need to restart Arduino to update\n"
+ + "the sketchbook menu."), null);
}
};
@@ -2273,7 +2258,8 @@ public void handleAddLibrary() {
ZipDeflater zipDeflater = new ZipDeflater(sourceFile, tmpFolder);
zipDeflater.deflate();
File[] foldersInTmpFolder = tmpFolder.listFiles(new OnlyDirs());
- if (foldersInTmpFolder.length != 1) {
+ /*if (Objects.requireNonNull(foldersInTmpFolder).length != 1) {*/
+ if (foldersInTmpFolder != null && foldersInTmpFolder.length != 1) {
throw new IOException(tr("Zip doesn't contain a library"));
}
sourceFile = foldersInTmpFolder[0];
diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java
index 9ba3a144b95..2379e203fe0 100644
--- a/app/src/processing/app/Editor.java
+++ b/app/src/processing/app/Editor.java
@@ -110,7 +110,7 @@
/**
* Main editor panel for the Processing Development Environment.
*/
-@SuppressWarnings("serial")
+@SuppressWarnings({"serial", "MagicConstant"})
public class Editor extends JFrame implements RunnerListener {
public static final int MAX_TIME_AWAITING_FOR_RESUMING_SERIAL_MONITOR = 10000;
@@ -588,7 +588,7 @@ private JMenu buildFileMenu() {
base.rebuildRecentSketchesMenuItems();
recentSketchesMenu = new JMenu(tr("Open Recent"));
- SwingUtilities.invokeLater(() -> rebuildRecentSketchesMenu());
+ SwingUtilities.invokeLater(this::rebuildRecentSketchesMenu);
fileMenu.add(recentSketchesMenu);
if (sketchbookMenu == null) {
@@ -794,15 +794,13 @@ private void addTools(JMenu menu, File sourceFolder) {
Map toolItems = new HashMap<>();
- File[] folders = sourceFolder.listFiles(new FileFilter() {
- public boolean accept(File folder) {
- if (folder.isDirectory()) {
- //System.out.println("checking " + folder);
- File subfolder = new File(folder, "tool");
- return subfolder.exists();
- }
- return false;
+ File[] folders = sourceFolder.listFiles(folder -> {
+ if (folder.isDirectory()) {
+ //System.out.println("checking " + folder);
+ File subfolder = new File(folder, "tool");
+ return subfolder.exists();
}
+ return false;
});
if (folders == null || folders.length == 0) {
@@ -817,14 +815,10 @@ public boolean accept(File folder) {
//urlList.add(toolDirectory.toURL());
// add .jar files to classpath
- File[] archives = toolDirectory.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return (name.toLowerCase().endsWith(".jar") ||
- name.toLowerCase().endsWith(".zip"));
- }
- });
+ File[] archives = toolDirectory.listFiles((dir, name) -> (name.toLowerCase().endsWith(".jar") ||
+ name.toLowerCase().endsWith(".zip")));
- URL[] urlList = new URL[archives.length];
+ URL[] urlList = archives != null ? new URL[archives.length] : new URL[0];
for (int j = 0; j < urlList.length; j++) {
urlList[j] = archives[j].toURI().toURL();
}
@@ -1057,12 +1051,7 @@ private void populatePortMenu() {
ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
- Collections.sort(ports, new Comparator() {
- @Override
- public int compare(BoardPort o1, BoardPort o2) {
- return BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol()) - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol());
- }
- });
+ ports.sort(Comparator.comparingInt(o -> BOARD_PROTOCOLS_ORDER.indexOf(o.getProtocol())));
String lastProtocol = null;
String lastProtocolTranslated;
@@ -1145,7 +1134,7 @@ private JMenu buildHelpMenu() {
menu.addSeparator();
item = newJMenuItemShift(tr("Find in Reference"), 'F');
- item.addActionListener(event -> handleFindReference(event));
+ item.addActionListener(this::handleFindReference);
menu.add(item);
item = new JMenuItem(tr("Frequently Asked Questions"));
@@ -1168,6 +1157,7 @@ private JMenu buildHelpMenu() {
}
+
private JMenu buildEditMenu() {
JMenu menu = new JMenu(tr("Edit"));
menu.setName("menuEdit");
diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java
index 8c5fb86a7d8..121952585b9 100644
--- a/app/src/processing/app/EditorTab.java
+++ b/app/src/processing/app/EditorTab.java
@@ -210,44 +210,24 @@ private void configurePopupMenu(final SketchTextArea textarea){
menu.add(item);
item = new JMenuItem(tr("Comment/Uncomment"), '/');
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleCommentUncomment();
- }
- });
+ item.addActionListener(e -> handleCommentUncomment());
menu.add(item);
item = new JMenuItem(tr("Increase Indent"), ']');
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleIndentOutdent(true);
- }
- });
+ item.addActionListener(e -> handleIndentOutdent(true));
menu.add(item);
item = new JMenuItem(tr("Decrease Indent"), '[');
item.setName("menuDecreaseIndent");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleIndentOutdent(false);
- }
- });
+ item.addActionListener(e -> handleIndentOutdent(false));
menu.add(item);
item = new JMenuItem(tr("Copy for Forum"));
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleDiscourseCopy();
- }
- });
+ item.addActionListener(e -> handleDiscourseCopy());
menu.add(item);
item = new JMenuItem(tr("Copy as HTML"));
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- handleHTMLCopy();
- }
- });
+ item.addActionListener(e -> handleHTMLCopy());
menu.add(item);
final JMenuItem referenceItem = new JMenuItem(tr("Find in Reference"));
@@ -255,11 +235,7 @@ public void actionPerformed(ActionEvent e) {
menu.add(referenceItem);
final JMenuItem openURLItem = new JMenuItem(tr("Open URL"));
- openURLItem.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Base.openURL(e.getActionCommand());
- }
- });
+ openURLItem.addActionListener(e -> Base.openURL(e.getActionCommand()));
menu.add(openURLItem);
menu.addPopupMenuListener(new PopupMenuListener() {
diff --git a/app/src/processing/app/NetworkMonitor.java b/app/src/processing/app/NetworkMonitor.java
index b7f08026ace..1d39ae5929c 100644
--- a/app/src/processing/app/NetworkMonitor.java
+++ b/app/src/processing/app/NetworkMonitor.java
@@ -34,18 +34,16 @@ public class NetworkMonitor extends AbstractTextMonitor implements MessageConsum
public NetworkMonitor(BoardPort port) {
super(port);
- onSendCommand(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- try {
- OutputStream out = channel.getOutputStream();
- out.write(textField.getText().getBytes());
- out.write('\n');
- out.flush();
- } catch (IOException e) {
- e.printStackTrace();
- }
- textField.setText("");
+ onSendCommand(event -> {
+ try {
+ OutputStream out = channel.getOutputStream();
+ out.write(textField.getText().getBytes());
+ out.write('\n');
+ out.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
}
+ textField.setText("");
});
}
@@ -101,20 +99,15 @@ private void tryConnect() throws JSchException, IOException {
new MessageSiphon(errStream, this);
if (connectionAttempts > 1) {
- SwingUtilities.invokeLater(new Runnable() {
-
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // ignore
- }
- if (channel.isConnected()) {
- NetworkMonitor.this.message(tr("connected!") + '\n');
- }
+ SwingUtilities.invokeLater(() -> {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ if (channel.isConnected()) {
+ NetworkMonitor.this.message(tr("connected!") + '\n');
}
-
});
}
}
@@ -132,16 +125,13 @@ public synchronized void message(String s) {
if (connectionAttempts < MAX_CONNECTION_ATTEMPTS) {
s = "\n" + tr("Unable to connect: retrying") + " (" + connectionAttempts + ")... ";
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- NetworkMonitor.this.tryConnect();
- } catch (JSchException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ SwingUtilities.invokeLater(() -> {
+ try {
+ NetworkMonitor.this.tryConnect();
+ } catch (JSchException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
}
});
} else {
diff --git a/app/src/processing/app/SerialMonitor.java b/app/src/processing/app/SerialMonitor.java
index 45adbd7d54b..b79161402f9 100644
--- a/app/src/processing/app/SerialMonitor.java
+++ b/app/src/processing/app/SerialMonitor.java
@@ -38,36 +38,28 @@ public SerialMonitor(BoardPort port) {
serialRate = PreferencesData.getInteger("serial.debug_rate");
serialRates.setSelectedItem(serialRate + " " + tr("baud"));
- onSerialRateChange(new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- String wholeString = (String) serialRates.getSelectedItem();
- String rateString = wholeString.substring(0, wholeString.indexOf(' '));
- serialRate = Integer.parseInt(rateString);
- PreferencesData.set("serial.debug_rate", rateString);
- try {
- close();
- Thread.sleep(100); // Wait for serial port to properly close
- open();
- } catch (InterruptedException e) {
- // noop
- } catch (Exception e) {
- System.err.println(e);
- }
+ onSerialRateChange(event -> {
+ String wholeString = (String) serialRates.getSelectedItem();
+ String rateString = wholeString.substring(0, wholeString.indexOf(' '));
+ serialRate = Integer.parseInt(rateString);
+ PreferencesData.set("serial.debug_rate", rateString);
+ try {
+ close();
+ Thread.sleep(100); // Wait for serial port to properly close
+ open();
+ } catch (InterruptedException e) {
+ // noop
+ } catch (Exception e) {
+ System.err.println(e);
}
});
- onSendCommand(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- send(textField.getText());
- textField.setText("");
- }
+ onSendCommand(e -> {
+ send(textField.getText());
+ textField.setText("");
});
- onClearCommand(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textArea.setText("");
- }
- });
+ onClearCommand(e -> textArea.setText(""));
}
private void send(String s) {
diff --git a/app/src/processing/app/TextAreaFIFO.java b/app/src/processing/app/TextAreaFIFO.java
index abf953dfd93..38a5007b05e 100644
--- a/app/src/processing/app/TextAreaFIFO.java
+++ b/app/src/processing/app/TextAreaFIFO.java
@@ -45,11 +45,7 @@ public TextAreaFIFO(int max) {
public void insertUpdate(DocumentEvent e) {
if (++updateCount > 150 && doTrim) {
updateCount = 0;
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- trimDocument();
- }
- });
+ SwingUtilities.invokeLater(() -> trimDocument());
}
}
diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java
index d38875b3597..a2fa11611b5 100644
--- a/app/src/processing/app/Theme.java
+++ b/app/src/processing/app/Theme.java
@@ -47,13 +47,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
+import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -371,7 +365,7 @@ static private void refreshAvailableThemes(Map discoveredTh
return;
}
- for (File zipFile : folder.listFiles((dir, name) -> name.endsWith(".zip"))) {
+ for (File zipFile : Objects.requireNonNull(folder.listFiles((dir, name) -> name.endsWith(".zip")))) {
ZippedTheme theme = ZippedTheme.load(namespace, zipFile);
if (theme != null) {
discoveredThemes.put(theme.getKey(), theme);
@@ -605,8 +599,8 @@ static public Image getThemeImage(String name, Component who, int width,
private static Image imageFromSVG(URL url, int width, int height)
throws TranscoderException {
Transcoder t = new PNGTranscoder();
- t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width));
- t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height));
+ t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) width);
+ t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height);
TranscoderInput input = new TranscoderInput(url.toString());
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
diff --git a/app/src/processing/app/macosx/ThinkDifferent.java b/app/src/processing/app/macosx/ThinkDifferent.java
index e946bdc0fd7..05f4f9412c3 100644
--- a/app/src/processing/app/macosx/ThinkDifferent.java
+++ b/app/src/processing/app/macosx/ThinkDifferent.java
@@ -45,61 +45,41 @@ public class ThinkDifferent {
static public void init() {
Application application = Application.getApplication();
- application.setAboutHandler(new AboutHandler() {
- @Override
- public void handleAbout(AppEvent.AboutEvent aboutEvent) {
- new Thread(() -> {
- if (waitForBase()) {
- Base.INSTANCE.handleAbout();
- }
- }).start();
+ application.setAboutHandler(aboutEvent -> new Thread(() -> {
+ if (waitForBase()) {
+ Base.INSTANCE.handleAbout();
}
- });
- application.setPreferencesHandler(new PreferencesHandler() {
- @Override
- public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
- new Thread(() -> {
- if (waitForBase()) {
- Base.INSTANCE.handlePrefs();
- }
- }).start();
+ }).start());
+ application.setPreferencesHandler(preferencesEvent -> new Thread(() -> {
+ if (waitForBase()) {
+ Base.INSTANCE.handlePrefs();
}
- });
- application.setOpenFileHandler(new OpenFilesHandler() {
- @Override
- public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
- new Thread(() -> {
- if (waitForBase()) {
- for (File file : openFilesEvent.getFiles()) {
- System.out.println(file);
- try {
- Base.INSTANCE.handleOpen(file);
- List editors = Base.INSTANCE.getEditors();
- if (editors.size() == 2 && editors.get(0).getSketchController().isUntitled()) {
- Base.INSTANCE.handleClose(editors.get(0));
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ }).start());
+ application.setOpenFileHandler(openFilesEvent -> new Thread(() -> {
+ if (waitForBase()) {
+ for (File file : openFilesEvent.getFiles()) {
+ System.out.println(file);
+ try {
+ Base.INSTANCE.handleOpen(file);
+ List editors = Base.INSTANCE.getEditors();
+ if (editors.size() == 2 && editors.get(0).getSketchController().isUntitled()) {
+ Base.INSTANCE.handleClose(editors.get(0));
}
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
- }).start();
+ }
}
- });
- application.setQuitHandler(new QuitHandler() {
- @Override
- public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
- new Thread(() -> {
- if (waitForBase()) {
- if (Base.INSTANCE.handleQuit()) {
- quitResponse.performQuit();
- } else {
- quitResponse.cancelQuit();
- }
- }
- }).start();
+ }).start());
+ application.setQuitHandler((quitEvent, quitResponse) -> new Thread(() -> {
+ if (waitForBase()) {
+ if (Base.INSTANCE.handleQuit()) {
+ quitResponse.performQuit();
+ } else {
+ quitResponse.cancelQuit();
+ }
}
- });
+ }).start());
}
private static boolean waitForBase() {
diff --git a/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java b/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java
index 126d684a6cf..e472b11529f 100644
--- a/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java
+++ b/app/src/processing/app/syntax/SketchTextAreaDefaultInputMap.java
@@ -11,6 +11,7 @@
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
+@SuppressWarnings("MagicConstant")
public class SketchTextAreaDefaultInputMap extends RSyntaxTextAreaDefaultInputMap {
public SketchTextAreaDefaultInputMap() {
diff --git a/app/src/processing/app/tools/MenuScroller.java b/app/src/processing/app/tools/MenuScroller.java
index 3523ec7ceca..22fb8a9afc8 100644
--- a/app/src/processing/app/tools/MenuScroller.java
+++ b/app/src/processing/app/tools/MenuScroller.java
@@ -296,19 +296,9 @@ public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
menu.addPopupMenuListener(menuListener);
menu.addMouseWheelListener(mouseWheelListener);
- ActionListener accel = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- accelerator = 6;
- }
- };
+ ActionListener accel = e -> accelerator = 6;
- ActionListener decel = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- accelerator = 1;
- }
- };
+ ActionListener decel = e -> accelerator = 1;
KeyStroke keystroke_accel = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, false);
KeyStroke keystroke_decel = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, true);
diff --git a/app/src/processing/app/tools/ZipDeflater.java b/app/src/processing/app/tools/ZipDeflater.java
index 1425d880247..de2c7d460cf 100644
--- a/app/src/processing/app/tools/ZipDeflater.java
+++ b/app/src/processing/app/tools/ZipDeflater.java
@@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
+import java.util.Objects;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
@@ -68,7 +69,7 @@ public void deflate() throws IOException {
}
private void deleteUndesiredFoldersAndFiles(File folder) {
- for (File file : folder.listFiles()) {
+ for (File file : Objects.requireNonNull(folder.listFiles())) {
if (file.isDirectory() && "__MACOSX".equals(file.getName())) {
FileUtils.recursiveDelete(file);
} else if (file.getName().startsWith(".")) {
@@ -89,7 +90,7 @@ private void ensureFoldersOfEntryExist(File folder, ZipEntry entry) {
private void ensureOneLevelFolder(File folder) {
File[] files = folder.listFiles();
- if (files.length != 1) {
+ if (Objects.requireNonNull(files).length != 1) {
folder.renameTo(new File(folder.getParentFile(), folderNameFromZip()));
return;
}
diff --git a/arduino-core/.classpath b/arduino-core/.classpath
index 9bc707f562a..dc312834da2 100644
--- a/arduino-core/.classpath
+++ b/arduino-core/.classpath
@@ -11,7 +11,7 @@
-
+
diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java
index ad7a964b466..92db53cd0f6 100644
--- a/arduino-core/src/cc/arduino/Compiler.java
+++ b/arduino-core/src/cc/arduino/Compiler.java
@@ -49,10 +49,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -274,7 +271,7 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
cmd.add("-prefs=build.warn_data_percentage=" + PreferencesData.get("build.warn_data_percentage"));
- for (Map.Entry entry : BaseNoGui.getBoardPreferences().entrySet()) {
+ for (Map.Entry entry : Objects.requireNonNull(BaseNoGui.getBoardPreferences()).entrySet()) {
if (entry.getKey().startsWith("runtime.tools")) {
cmd.add("-prefs=" + entry.getKey() + "=" + entry.getValue());
}
@@ -390,8 +387,7 @@ private boolean isExportCompiledSketchSupported(List compiledSketches, L
}
private void runActions(String recipeClass, PreferencesMap prefs) throws RunnerException, PreferencesMapException {
- List patterns = prefs.keySet().stream().filter(key -> key.startsWith("recipe." + recipeClass) && key.endsWith(".pattern")).collect(Collectors.toList());
- Collections.sort(patterns);
+ List patterns = prefs.keySet().stream().filter(key -> key.startsWith("recipe." + recipeClass) && key.endsWith(".pattern")).sorted().collect(Collectors.toList());
for (String recipe : patterns) {
runRecipe(recipe, prefs);
}
diff --git a/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java b/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java
index 3aa1198882c..41e37fda6a9 100644
--- a/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java
+++ b/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java
@@ -88,10 +88,7 @@ public void unsetInstalledUserLibrary() {
}
public boolean isIDEBuiltIn() {
- if (!installedLib.isPresent()) {
- return false;
- }
- return installedLib.get().isIDEBuiltIn();
+ return installedLib.map(UserLibrary::isIDEBuiltIn).orElse(false);
}
/**
diff --git a/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibraryReleases.java b/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibraryReleases.java
index 7a2a75a4498..593fd5e3459 100644
--- a/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibraryReleases.java
+++ b/arduino-core/src/cc/arduino/contributions/libraries/ContributedLibraryReleases.java
@@ -77,6 +77,7 @@ public void add(ContributedLibrary library) {
selected = latest;
}
+ @SuppressWarnings("OptionalGetWithoutIsPresent")
public Optional getInstalled() {
return releases.stream() //
.filter(ContributedLibrary::isLibraryInstalled) //
diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java
index f06cc736bbf..fcd7afd1ba1 100644
--- a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java
+++ b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java
@@ -83,7 +83,7 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E
rescanLibraryIndex(progress, progressListener);
}
- public synchronized void install(ContributedLibrary lib, Optional mayReplacedLib, ProgressListener progressListener) throws Exception {
+ public synchronized void install(ContributedLibrary lib, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional mayReplacedLib, ProgressListener progressListener) throws Exception {
if (lib.isLibraryInstalled()) {
System.out.println(I18n.format(tr("Library is already installed: {0}:{1}"), lib.getName(), lib.getParsedVersion()));
return;
diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java
index 1ec4c365faa..1c153b25160 100644
--- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java
+++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java
@@ -100,7 +100,7 @@ public void parseIndex() throws Exception {
// Overlay 3rd party indexes
File[] indexFiles = preferencesFolder.listFiles(new TestPackageIndexFilenameFilter(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME)));
- for (File indexFile : indexFiles) {
+ for (File indexFile : Objects.requireNonNull(indexFiles)) {
try {
mergeContributions(indexFile);
} catch (JsonProcessingException e) {
@@ -399,7 +399,7 @@ public Set getInstalledTools() {
}
for (ContributedPackage pack : index.getPackages()) {
Collection platforms = pack.getPlatforms().stream() //
- .filter(p -> p.isInstalled()) //
+ .filter(ContributedPlatform::isInstalled) //
.collect(Collectors.toList());
Map> platformsByName = platforms.stream().collect(Collectors.groupingBy(ContributedPlatform::getName));
diff --git a/arduino-core/src/cc/arduino/i18n/ExternalProcessOutputParser.java b/arduino-core/src/cc/arduino/i18n/ExternalProcessOutputParser.java
index 7486ce4fb94..5d0e4d6cff3 100644
--- a/arduino-core/src/cc/arduino/i18n/ExternalProcessOutputParser.java
+++ b/arduino-core/src/cc/arduino/i18n/ExternalProcessOutputParser.java
@@ -90,7 +90,7 @@ private List addAsManyEmptyArgsAsEndingSpaces(String argsAsString, List<
List additionalArgs = new LinkedList<>();
if (argsAsString.charAt(argsAsString.length() - 1) == ' ') {
- String allArgsButEndingSpacesAsString = args.stream().collect(Collectors.joining(" "));
+ String allArgsButEndingSpacesAsString = String.join(" ", args);
String endingSpacesOnly = argsAsString.replace(allArgsButEndingSpacesAsString, "");
for (int i = 0; i < endingSpacesOnly.length(); i++) {
additionalArgs.add("");
diff --git a/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java
index 4de78552c97..0bda4142771 100644
--- a/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java
+++ b/arduino-core/src/cc/arduino/packages/discoverers/SerialDiscovery.java
@@ -63,7 +63,7 @@ private List getSerialBoardPorts(boolean complete) {
}
List onlineBoardPorts = new LinkedList<>();
for (BoardPort port : serialBoardPorts) {
- if (port.isOnline() == true) {
+ if (port.isOnline()) {
onlineBoardPorts.add(port);
}
}
diff --git a/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java b/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
index a6f34b265d2..285a65e803f 100644
--- a/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
+++ b/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
@@ -43,17 +43,11 @@ public void merge(File sketch, File bootloader) throws IOException {
mergedSketch.remove(mergedSketch.size() - 1);
mergedSketch.addAll(FileUtils.readFileToListOfStrings(bootloader));
- FileWriter writer = null;
- try {
- writer = new FileWriter(sketch);
+ try (FileWriter writer = new FileWriter(sketch)) {
for (String line : mergedSketch) {
writer.write(line);
writer.write("\n");
}
- } finally {
- if (writer != null) {
- writer.close();
- }
}
}
diff --git a/arduino-core/src/processing/app/Sketch.java b/arduino-core/src/processing/app/Sketch.java
index 6c417403ec9..ab4a42ee950 100644
--- a/arduino-core/src/processing/app/Sketch.java
+++ b/arduino-core/src/processing/app/Sketch.java
@@ -31,15 +31,12 @@ public class Sketch {
private File buildPath;
- public static final Comparator CODE_DOCS_COMPARATOR = new Comparator() {
- @Override
- public int compare(SketchFile x, SketchFile y) {
- if (x.isPrimary() && !y.isPrimary())
- return -1;
- if (y.isPrimary() && !x.isPrimary())
- return 1;
- return x.getFileName().compareTo(y.getFileName());
- }
+ public static final Comparator CODE_DOCS_COMPARATOR = (x, y) -> {
+ if (x.isPrimary() && !y.isPrimary())
+ return -1;
+ if (y.isPrimary() && !x.isPrimary())
+ return 1;
+ return x.getFileName().compareTo(y.getFileName());
};
/**
@@ -316,7 +313,7 @@ public SketchFile addFile(String newName) throws IOException {
// Add a new sketchFile
SketchFile sketchFile = new SketchFile(this, newFile);
files.add(sketchFile);
- Collections.sort(files, CODE_DOCS_COMPARATOR);
+ files.sort(CODE_DOCS_COMPARATOR);
return sketchFile;
}
diff --git a/arduino-core/src/processing/app/debug/MessageSiphon.java b/arduino-core/src/processing/app/debug/MessageSiphon.java
index ca0a7fcaa19..af63757cf8d 100644
--- a/arduino-core/src/processing/app/debug/MessageSiphon.java
+++ b/arduino-core/src/processing/app/debug/MessageSiphon.java
@@ -112,17 +112,15 @@ public void run() {
currentLine.setLength(0);
}
//EditorConsole.systemOut.println("messaging thread done");
- } catch (NullPointerException npe) {
+ } catch (NullPointerException | SocketException npe) {
// Fairly common exception during shutdown
- } catch (SocketException e) {
- // socket has been close while we were wainting for data. nothing to see here, move along
} catch (Exception e) {
// On Linux and sometimes on Mac OS X, a "bad file descriptor"
// message comes up when closing an applet that's run externally.
// That message just gets supressed here..
String mess = e.getMessage();
if ((mess != null) &&
- (mess.indexOf("Bad file descriptor") != -1)) {
+ (mess.contains("Bad file descriptor"))) {
//if (e.getMessage().indexOf("Bad file descriptor") == -1) {
//System.err.println("MessageSiphon err " + e);
//e.printStackTrace();
diff --git a/arduino-core/src/processing/app/helpers/FileUtils.java b/arduino-core/src/processing/app/helpers/FileUtils.java
index 5e30319dc6a..a39c28f7426 100644
--- a/arduino-core/src/processing/app/helpers/FileUtils.java
+++ b/arduino-core/src/processing/app/helpers/FileUtils.java
@@ -56,7 +56,7 @@ public static void copyFile(File source, File dest) throws IOException {
}
public static void copy(File sourceFolder, File destFolder) throws IOException {
- for (File file : sourceFolder.listFiles()) {
+ for (File file : Objects.requireNonNull(sourceFolder.listFiles())) {
File destFile = new File(destFolder, file.getName());
if (file.isDirectory() && !SOURCE_CONTROL_FOLDERS.contains(file.getName())) {
if (!destFile.exists() && !destFile.mkdir()) {
@@ -142,7 +142,7 @@ public static String relativePath(String origin, String target) {
String prefix = "";
String root = File.separator;
- if (System.getProperty("os.name").indexOf("Windows") != -1) {
+ if (System.getProperty("os.name").contains("Windows")) {
if (origin.startsWith("\\\\") || target.startsWith("\\\\")) {
// Windows UNC path not supported.
return null;
@@ -211,19 +211,13 @@ public static String readFileToString(File file, String encoding) throws IOExcep
public static List readFileToListOfStrings(File file) throws IOException {
List strings = new LinkedList<>();
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader(file));
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.replaceAll("\r", "").replaceAll("\n", "").replaceAll(" ", "");
strings.add(line);
}
return strings;
- } finally {
- if (reader != null) {
- reader.close();
- }
}
}
diff --git a/arduino-core/src/processing/app/helpers/NetUtils.java b/arduino-core/src/processing/app/helpers/NetUtils.java
index 17dc52c8617..c5b3d2c4287 100644
--- a/arduino-core/src/processing/app/helpers/NetUtils.java
+++ b/arduino-core/src/processing/app/helpers/NetUtils.java
@@ -35,21 +35,12 @@ public static boolean isReachable(InetAddress address, List ports) {
}
private static boolean isPortOpen(InetAddress address, int port) {
- Socket socket = null;
- try {
- socket = new Socket();
+ try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(address, port), 1000);
return true;
} catch (IOException e) {
return false;
- } finally {
- if (socket != null) {
- try {
- socket.close();
- } catch (IOException e) {
- // noop
- }
- }
}
+ // noop
}
}
diff --git a/arduino-core/src/processing/app/helpers/StringReplacer.java b/arduino-core/src/processing/app/helpers/StringReplacer.java
index 159289d1d5b..52d772e01ed 100644
--- a/arduino-core/src/processing/app/helpers/StringReplacer.java
+++ b/arduino-core/src/processing/app/helpers/StringReplacer.java
@@ -94,7 +94,7 @@ public static String replaceFromMapping(String src, Map map,
String rightDelimiter) {
for (Map.Entry entry : map.entrySet()) {
String keyword = leftDelimiter + entry.getKey() + rightDelimiter;
- if (entry.getValue() != null && keyword != null) {
+ if (entry.getValue() != null) {
src = src.replace(keyword, entry.getValue());
}
}
diff --git a/arduino-core/src/processing/app/packages/LibraryList.java b/arduino-core/src/processing/app/packages/LibraryList.java
index cff1b7b123e..8fbbd86cd96 100644
--- a/arduino-core/src/processing/app/packages/LibraryList.java
+++ b/arduino-core/src/processing/app/packages/LibraryList.java
@@ -88,12 +88,12 @@ public static Collector collector() {
return new Collector() {
@Override
public Supplier supplier() {
- return () -> new LibraryList();
+ return LibraryList::new;
}
@Override
public BiConsumer accumulator() {
- return (libs, lib) -> libs.add(lib);
+ return LinkedList::add;
}
@Override