Skip to content

Commit

Permalink
Minor cleanup by findbugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Dec 25, 2023
1 parent d34b246 commit 1d5d0a6
Show file tree
Hide file tree
Showing 40 changed files with 93 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class AckWithMemoryDialog extends javax.swing.JDialog {
private final String message;
private final String uSureMessage;

@SuppressWarnings("PublicInnerClass")
public interface PropertyFlip {
public boolean getProperty();
public void setProperty(boolean value);
Expand All @@ -41,6 +42,7 @@ private AckWithMemoryDialog(String message, String uSure, PropertyFlip propertyF
initComponents();
}

@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
public static boolean ackWithMemoryDialog(String message, String uSure, PropertyFlip propertyFlip, Frame parent) {
if (propertyFlip.getProperty())
return true;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/harctoolbox/guicomponents/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public void toClipboard(String str) {
// return (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this).getTransferData(DataFlavor.stringFlavor);
//}
}
@SuppressWarnings("PublicInnerClass")
public interface IErrorFunction {
void err(Exception ex, String str);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

@SuppressWarnings("UseOfSystemOutOrSystemErr")
public class CopyClipboardText implements ClipboardOwner {

public static String getSelection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public GirsClientBean(GuiUtils guiUtils, boolean verbose) {
this(guiUtils, verbose, DEFAULT_TIMEOUT, DEFAULT_PORTNAME, DEFAULT_BAUD, DEFAULT_IPNAME, DEFAULT_PORT, DEFAULT_TYPE);
}

@SuppressWarnings("AssignmentToMethodParameter")
public GirsClientBean(GuiUtils guiUtils, boolean verbose, int timeout, String initialPort, int baud,
String ipName, int portNumber, Type type) {
super(guiUtils, verbose, timeout);
Expand Down Expand Up @@ -337,6 +338,7 @@ private void enableStuff(boolean isOpen) {
displayVersion();
}

@SuppressWarnings("PublicInnerClass")
public static enum Type {
SERIAL,
TCP,
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/harctoolbox/guicomponents/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -234,7 +233,7 @@ public String getInput(String message, String title, String defaultAnswer) {

public Integer getIntegerInput(String message, int oldValue) {
String s = getInput(message, "Parameter input", Integer.toString(oldValue));
return s != null ? Integer.parseInt(s) : null;
return s != null ? Integer.valueOf(s) : null;
}

public Long getLongInput(String message, long oldValue) {
Expand All @@ -246,7 +245,7 @@ public Long getLongInput(String message, long oldValue) {

public Double getDoubleInput(String message, double oldValue) {
String s = getInput(message, "Parameter input", Double.toString(oldValue));
return s != null ? Double.parseDouble(s) : null;
return s != null ? Double.valueOf(s) : null;
}

public boolean confirm(String message) {
Expand Down Expand Up @@ -297,6 +296,7 @@ else if (Desktop.isDesktopSupported())
* ... not omnipresent, use only this function.
*
* @param file file or directory to be opened/edited.
* @throws java.io.IOException
*/
public void open(File file) throws IOException {
if (useXdbOpen)
Expand Down Expand Up @@ -375,6 +375,7 @@ public boolean checkUpToDate(String currentVersionUrl, String versionString) {
return current != null && current.equals(versionString);
}

@SuppressWarnings("PublicInnerClass")
public interface EmergencyFixer {
public void fix();

Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/harctoolbox/guicomponents/HardwareBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
/**
* This is a superclass of all the hardware managing beans.
*/
@SuppressWarnings("serial")
public abstract class HardwareBean extends JPanel implements Closeable {

public static final String PROP_VERSION = "PROP_VERSION";
Expand Down Expand Up @@ -103,6 +104,7 @@ protected void openClose(boolean opening) throws IOException, HarcHardwareExcept

/**
* Returns a somewhat friendly name of the class.
* @return name
*/
@Override
public String getName() {
Expand Down Expand Up @@ -158,26 +160,40 @@ public boolean canSend() {
/**
* Default implementation, override whenever the subclass can capture.
* @return ModulatedSequence captured, or null.
* @throws org.harctoolbox.guicomponents.HardwareBean.CannotCaptureException
* @throws HarcHardwareException
* @throws InvalidArgumentException
* @throws IOException
*/
public ModulatedIrSequence capture() throws CannotCaptureException, HarcHardwareException, InvalidArgumentException, IOException {
throw new CannotCaptureException(getName());
}

/**
* Default implementation, override whenever the subclass can send.
* @return success of operation
*
* @param irSignal
* @param count
* @return success of operation
* @throws NoSuchTransmitterException
* @throws IOException
* @throws HardwareUnavailableException
* @throws HarcHardwareException
* @throws InvalidArgumentException
*/
public boolean sendIr(IrSignal irSignal, int count) throws NoSuchTransmitterException, IOException, HardwareUnavailableException, HarcHardwareException, InvalidArgumentException {
throw new CannotSendException(getName());
}

public static class CannotCaptureException extends HarcHardwareException {
@SuppressWarnings("PublicInnerClass")
public static class CannotCaptureException extends HarcHardwareException {

private CannotCaptureException(String name) {
super("Selected hardware " + name + " cannot capture.");
}
}

@SuppressWarnings("PublicInnerClass")
public static class CannotSendException extends HarcHardwareException {

public CannotSendException(String name) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/harctoolbox/guicomponents/IrPlotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public IrPlotter() {
this(true);
}

@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
public IrPlotter(IrPlotter irPlotter, boolean zoomSupport) {
this(zoomSupport);
this.noIntroBursts = irPlotter.noIntroBursts;
Expand Down Expand Up @@ -319,6 +320,7 @@ private void drawPlot(Graphics graphics) {
}
}

@SuppressWarnings("UseOfSystemOutOrSystemErr")
private int[] getTickValues(int xmin, int xmax, int pixelWidth) {
if (xmin == xmax)
return new int[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ public InputVariableSetValues getIntervalParameters() throws UnknownProtocolExce

public IrSignal render() throws IrpException, IrCoreException, ParseException {
Map<String, Long> parameters = getParameters();
IrSignal irSignal = protocol.toIrSignal(parameters);
return irSignal;
return protocol.toIrSignal(parameters);
}

public Map<String, Command> getCommands() throws IrCoreException, IrpException, ParseException, GirrException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public String getCurrentLAFClassName() {
/**
* Allows for error reporting function and a set-property function of the caller.
*/
@SuppressWarnings("PublicInnerClass")
public interface ILookAndFeelManagerCaller {
/**
* Used for error reporting through the caller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private MetaDataDialog(Remote.MetaData metaData, Frame parent) {
nameTextField.setText(DEFAULT_REMOTENAME);
}

@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
public static Remote.MetaData inquireMetaData(Remote.MetaData initData, Frame parent) {
MetaDataDialog dialog = new MetaDataDialog(initData, parent);
Rectangle parentCoords = parent.getBounds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
*
*/
@SuppressWarnings("serial")
public abstract class SerialHardwareBean extends HardwareBean {

protected static DefaultComboBoxModel<String> createModel(boolean useCached) {
Expand All @@ -40,8 +41,7 @@ protected static DefaultComboBoxModel<String> createModel(boolean useCached) {
portNames.add("");
}
//portNames.add(0, "");
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(portNames.toArray(new String[portNames.size()]));
return model;
return new DefaultComboBoxModel<>(portNames.toArray(new String[portNames.size()]));
}

protected String portName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private static boolean errorContinue(String message) {
return ans == 0;
}

@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void main(String[] args) {
try {
boolean result = errorContinue(args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private String last() {
}
}

@SuppressWarnings({"PublicInnerClass", "serial"})
public static class UndoHistoryEmptyException extends Exception {

public UndoHistoryEmptyException() {
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.comm.DriverGenUnix;
import javax.swing.DefaultComboBoxModel;
Expand Down Expand Up @@ -1337,12 +1336,12 @@ private File saveCommands(Map<String, Command> commands, String title, Exporter
guiUtils.error("No exporter");
return null;
}

if (commands.isEmpty()) {
guiUtils.error("Nothing to export");
return null;
}

File savedFile;
if (commands.size() == 1) {
savedFile = saveSignalWrite(commands.values().iterator().next(), title, exporter);
Expand All @@ -1353,7 +1352,7 @@ private File saveCommands(Map<String, Command> commands, String title, Exporter
}
savedFile = saveCommandsWrite(commands, title, (RemoteSetExporter) exporter);
}

if (savedFile != null) {
guiUtils.message("File " + savedFile + " was successfully written with " + commands.size() + (commands.size() == 1 ? " command." : " commands."));
if (properties.getAutoOpenExports())
Expand Down Expand Up @@ -1409,15 +1408,6 @@ private File saveSignalWrite(Command command, String title, Exporter exporter) t
new File(properties.getExportDir()), properties.getExportCharsetName());
}

private double getFrequency() {
try {
return Double.parseDouble(frequencyLabel.getText());
} catch (NumberFormatException | NullPointerException ex) {
}
double f = properties.getFallbackFrequency();
return f > 0 ? f : ModulatedIrSequence.DEFAULT_FREQUENCY;
}

private void reAnalyze() {
try {
IrSignal irSignal = getCapturedIrSignal();
Expand Down Expand Up @@ -7414,8 +7404,8 @@ private void editingTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//
Class<?> clazz = tableModel.getColumnClass(column);
String str = editingTextField.getText();
Object thing = str.trim().isEmpty() ? null
: clazz == Integer.class ? Integer.parseInt(str)
: clazz == Boolean.class ? Boolean.parseBoolean(str)
: clazz == Integer.class ? Integer.valueOf(str)
: clazz == Boolean.class ? Boolean.valueOf(str)
: str;

Object oldValue = tableModel.getValueAt(r, c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private static void doExit(int exitcode) {
/**
* @param args the command line arguments.
*/
@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
public static void main(String[] args) {
argumentParser = new JCommander(commandLineArgs);
argumentParser.setProgramName(Version.appName);
Expand Down Expand Up @@ -116,6 +117,7 @@ public static void setupRadixPrefixes() {
IrCoreUtils.setRadixPrefixes(map);
}

@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
private static String nukeProperties(boolean verbose) {
Props properties = new Props(commandLineArgs.propertiesFilename, commandLineArgs.applicationHome);
String filename = properties.getFilename();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*
*
*/
@SuppressWarnings({"PackageVisibleInnerClass", "serial", "UseOfSystemOutOrSystemErr"})
abstract class NamedIrSignal {
private static int count = 0;

Expand Down Expand Up @@ -225,6 +226,7 @@ public void removeColumns(Collection<Integer> list) {
public abstract static class LearnedIrSignalTableModel extends DefaultTableModel {
private final AbstractColumnFunction columnsFunc;
private boolean scrollRequest = false;
@SuppressWarnings("PackageVisibleField")
protected boolean unsavedChanges;

protected LearnedIrSignalTableModel(AbstractColumnFunction columnFunc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
*
*/
@SuppressWarnings({"PackageVisibleInnerClass", "serial", "AccessingNonPublicFieldOfAnotherObject"})
class ParametrizedIrSignal extends NamedIrSignal {
private static Decoder decoder = null;
private static Decoder.DecoderParameters decoderParameters = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/harctoolbox/irscrutinizer/RawIrSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* Note: Editing of the sequences is not implemented (yet).
*
*/
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "PackageVisibleInnerClass"})
class RawIrSignal extends NamedIrSignal {

private static Decoder decoder = null;
Expand Down Expand Up @@ -186,8 +187,7 @@ private void setIrSignal(ModulatedIrSequence irSequence) {
}

public Command toCommand() {
Command command = new Command(getName(), getComment(), irSignal);
return command;
return new Command(getName(), getComment(), irSignal);
}

public IrSignal getIrSignal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ private static Map<String, IExporterFactory> parseExportFormatsFile(GuiUtils gui

static DocumentFragment extractDocumentation(Element el) {
NodeList nodeList = el.getElementsByTagNameNS(EXPORTFORMAT_NAMESPACE, "documentation");
DocumentFragment doc = nodeList.getLength() > 0 ? nodeListToDocumentFragment(nodeList, true) : null;
return doc;
return nodeList.getLength() > 0 ? nodeListToDocumentFragment(nodeList, true) : null;
}

private static DocumentFragment nodeToDocumentFragment(Node node, boolean preserve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static void doExit(int exitcode) {
System.exit(exitcode);
}

@SuppressWarnings("UseOfSystemOutOrSystemErr")
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "AccessingNonPublicFieldOfAnotherObject"})
public static void main(String[] args) {
argumentParser = new JCommander(commandLineArgs);
argumentParser.setProgramName("DynamicRemoteSetExportFormatVersion");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public String[] toArray() {
return list.toArray(new String[list.size()]);
}

@SuppressWarnings("PublicInnerClass")
public interface IExportFormatSelector {
public void select(String name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ private Remote loadDevice(CCFDevice dev) {

Map<String, String> notes = new HashMap<>(1);
notes.put("note", "Imported by IrScrutinizer");
Remote remote = new Remote(new Remote.MetaData(deviceName),
return new Remote(new Remote.MetaData(deviceName),
origin, //java.lang.String comment,
notes,//"Imported by IrScrutinizer", //java.lang.String notes,
commands,
null //java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.String>> applicationParameters)
);
return remote;
}

@SuppressWarnings("UseOfSystemOutOrSystemErr")
Expand Down
Loading

0 comments on commit 1d5d0a6

Please sign in to comment.