Skip to content

Commit a79e780

Browse files
authored
Merge pull request #133 from cicirello/fix
Misc improvements based on SpotBugs analysis
2 parents c7bc140 + 4b4d064 commit a79e780

23 files changed

+132
-73
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased] - 2023-08-05
7+
## [Unreleased] - 2023-08-06
88

99
### Added
1010

@@ -15,6 +15,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Removed
1616

1717
### Fixed
18+
* LogRecord.toString() changed to use platform-specific line separators.
19+
* LogRecord.equals(Object): correctly handle null and other types.
20+
* RecordList.equals(Object): correctly handle null and other types.
21+
* Bin.contentsToString(): StringBuilder instead of iterated concat.
22+
* SessionLog.moveCountToString(): StringBuilder instead of iterated concat.
23+
* SessionLogFormatter: fixed potential resource leak.
24+
* SessionLog: implemented readObject to properly initialize transient fields during deserialization.
25+
* Set most classes to package access.
1826

1927
### CI/CD
2028
* Integrated SpotBugs into build process.

spotbugs-exclude.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Bug pattern="PREDICTABLE_RANDOM" />
55
</Match>
66

7-
<!-- False positive -->
7+
<!-- False positive: using JFileChooser with filter to select file, SpotBugs complaining where extension is added if missing -->
88
<Match>
99
<Bug pattern="PATH_TRAVERSAL_IN" />
1010
<Class name="org.cicirello.ibp.MenuBar" />

src/main/java/org/cicirello/ibp/About.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2021 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -38,7 +38,7 @@
3838
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3939
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
4040
*/
41-
public class About extends JDialog {
41+
final class About extends JDialog {
4242

4343
/**
4444
* Constructs the About dialog.

src/main/java/org/cicirello/ibp/ApplicationState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2021 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -34,7 +34,7 @@
3434
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3535
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3636
*/
37-
public class ApplicationState {
37+
final class ApplicationState {
3838

3939
/** Practice mode where user is free to move items around as they see fit. */
4040
public static final int MODE_PRACTICE = 0;

src/main/java/org/cicirello/ibp/Bin.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2022 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -31,7 +31,7 @@
3131
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3232
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3333
*/
34-
public class Bin {
34+
class Bin {
3535

3636
private ArrayList<Item> contents;
3737
private int capacity;
@@ -214,17 +214,18 @@ public void removeAll() {
214214
* @return a String listing all of the objects in the bin
215215
*/
216216
public String contentsToString() {
217-
String result = "";
217+
StringBuilder result = new StringBuilder();
218218
int i = 0;
219219
for (; i < contents.size() - 1; i++) {
220-
result += contents.get(i) + ", ";
220+
result.append(contents.get(i));
221+
result.append(", ");
221222
}
222223
if (contents.size() > 0) {
223-
result += contents.get(i);
224+
result.append(contents.get(i));
224225
} else {
225-
result = "empty";
226+
result.append("empty");
226227
}
227-
return result;
228+
return result.toString();
228229
}
229230

230231
/**

src/main/java/org/cicirello/ibp/BottomPanel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2021 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -40,13 +40,13 @@
4040
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
4141
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
4242
*/
43-
public class BottomPanel extends JPanel {
43+
class BottomPanel extends JPanel {
4444

4545
/** Application. */
46-
private InteractiveBinPacking f;
46+
private final InteractiveBinPacking f;
4747

4848
/** Maintains application state. */
49-
private ApplicationState state;
49+
private final ApplicationState state;
5050

5151
/** Combo box of destinations. */
5252
private JComboBox<Bin> destinations;
@@ -55,7 +55,7 @@ public class BottomPanel extends JPanel {
5555
private JComboBox<Item> itemList;
5656

5757
/** Called when item moved. */
58-
private CallBack onMove;
58+
private final CallBack onMove;
5959

6060
/**
6161
* Constructs the panel.

src/main/java/org/cicirello/ibp/CallBack.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2021 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -27,7 +27,7 @@
2727
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
2828
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
2929
*/
30-
public interface CallBack {
30+
interface CallBack {
3131

3232
/** This is the callback method. */
3333
void call();

src/main/java/org/cicirello/ibp/CenterPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2021 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -35,13 +35,13 @@
3535
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3636
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3737
*/
38-
public class CenterPanel extends JPanel {
38+
final class CenterPanel extends JPanel {
3939

4040
/** Contents of the bins. */
41-
private ArrayList<JTextField> binContents;
41+
private final ArrayList<JTextField> binContents;
4242

4343
/** Maintains application state. */
44-
private ApplicationState state;
44+
private final ApplicationState state;
4545

4646
/**
4747
* Constructs the panel.

src/main/java/org/cicirello/ibp/Floor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2022 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -30,7 +30,7 @@
3030
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3131
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3232
*/
33-
public class Floor extends Bin {
33+
final class Floor extends Bin {
3434

3535
/**
3636
* Generates a random instance of the bin packing problem. Through the use of a seed for the

src/main/java/org/cicirello/ibp/Help.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Interactive Bin Packing.
3-
* Copyright (C) 2008, 2010, 2020-2021 Vincent A. Cicirello
3+
* Copyright (C) 2008, 2010, 2020-2023 Vincent A. Cicirello
44
*
55
* This file is part of Interactive Bin Packing.
66
*
@@ -29,7 +29,7 @@
2929
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3030
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3131
*/
32-
public class Help extends InfoDialog {
32+
final class Help extends InfoDialog {
3333

3434
/**
3535
* Constructs the Help dialog.

0 commit comments

Comments
 (0)