Skip to content

Commit f0f29d2

Browse files
authored
Fix unread fields and enforce URF SpotBugs violations (#4383)
* Fix unread fields and enforce URF violations * Fix PathMeasure length and restore Style cache * Preserve zeroed gzip mtime when reading * Propagate GZIP modified time from archive * Address remaining SpotBugs unread fields * Exclude GridBagLayoutInfo from unread-field checks
1 parent 085dde3 commit f0f29d2

File tree

24 files changed

+55
-82
lines changed

24 files changed

+55
-82
lines changed

.github/scripts/generate-quality-report.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ def main() -> None:
806806
"NP_BOOLEAN_RETURN_NULL",
807807
"REFLC_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_CLASS",
808808
"UI_INHERITANCE_UNSAFE_GETRESOURCE",
809+
"URF_UNREAD_FIELD",
809810
"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD",
810811
"UW_UNCOND_WAIT",
811812
"SIC_INNER_SHOULD_BE_STATIC_ANON",
@@ -818,6 +819,8 @@ def _is_exempt(f: Finding) -> bool:
818819
return True
819820
if f.rule == "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" and "TarEntry.java" in loc:
820821
return True
822+
if f.rule == "URF_UNREAD_FIELD" and "GridBagLayoutInfo" in loc:
823+
return True
821824
return False
822825

823826

CodenameOne/src/com/codename1/charts/compat/PathMeasure.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.codename1.charts.compat;
2424

2525
import com.codename1.ui.geom.GeneralPath;
26+
import com.codename1.ui.geom.Rectangle;
2627

2728

2829
/**
@@ -31,16 +32,23 @@
3132
*/
3233
public class PathMeasure {
3334

34-
GeneralPath path;
35-
boolean forceClosed = false;
35+
private final GeneralPath path;
36+
private final boolean forceClosed;
3637

3738
public PathMeasure(GeneralPath p, boolean b) {
3839
path = p;
3940
forceClosed = b;
41+
if (forceClosed && path != null) {
42+
path.closePath();
43+
}
4044
}
4145

4246
public float getLength() {
43-
return 10;
47+
if (path == null) {
48+
return 0;
49+
}
50+
Rectangle bounds = path.getBounds();
51+
return (float) Math.max(bounds.getWidth(), bounds.getHeight());
4452
}
4553

4654
public void getPosTan(int i, float[] coords, float[] tan) {

CodenameOne/src/com/codename1/charts/views/BarChart.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,11 @@ public void drawSeries(Canvas canvas, Paint paint, List<Float> points,
122122
int seriesNr = mDataset.getSeriesCount();
123123
int length = points.size();
124124
paint.setColor(seriesRenderer.getColor());
125-
paint.setStyle(Style.FILL);
126-
float halfDiffX = getHalfDiffX(points, length, seriesNr);
127-
128-
Point[] yvals = new Point[length / 2];
129-
for (int i = 0; i < length; i += 2) {
130-
Point p = new Point();
131-
p.seriesIndex = i / 2;
132-
p.yval = points.get(i + 1);
133-
yvals[i / 2] = p;
134-
}
135-
136-
137-
for (int i = 0; i < length; i += 2) {
138-
float x = points.get(i);
139-
float y = points.get(i + 1);
125+
paint.setStyle(Style.FILL);
126+
float halfDiffX = getHalfDiffX(points, length, seriesNr);
127+
for (int i = 0; i < length; i += 2) {
128+
float x = points.get(i);
129+
float y = points.get(i + 1);
140130

141131
if (mType == Type.HEAPED && seriesIndex > 0) {
142132
float lastY = mPreviousSeriesPoints.get(i + 1);

CodenameOne/src/com/codename1/components/InfiniteScrollAdapter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class InfiniteScrollAdapter {
5555
private final Component ip;
5656
private int componentLimit = -1;
5757
private final InfiniteProgress progress;
58-
private final Component endMarker = new EdgeMarker(true);
58+
private final Component endMarker = new EdgeMarker();
5959

6060
private InfiniteScrollAdapter() {
6161
progress = new InfiniteProgress();
@@ -225,10 +225,7 @@ public InfiniteProgress getInfiniteProgress() {
225225
}
226226

227227
class EdgeMarker extends Component {
228-
private final boolean top;
229-
230-
public EdgeMarker(boolean top) {
231-
this.top = top;
228+
public EdgeMarker() {
232229
}
233230

234231
public Dimension calcPreferredSize() {

CodenameOne/src/com/codename1/components/SplitPane.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ public SplitPane(Settings settings, Component topOrLeft, Component bottomOrRight
204204
this.showDragHandle = settings.showDragHandle;
205205
this.showExpandCollapseButtons = settings.showExpandCollapseButtons;
206206
this.dividerUIID = settings.dividerUIID;
207+
this.expandMaterialIcon = settings.expandMaterialIcon;
208+
this.collapseMaterialIcon = settings.collapseMaterialIcon;
209+
this.dragHandleMaterialIcon = settings.dragHandleMaterialIcon;
210+
this.expandIcon = settings.expandIcon;
211+
this.collapseIcon = settings.collapseIcon;
212+
this.dragHandleIcon = settings.dragHandleIcon;
207213

208214
divider = new Divider();
209215
add(this.topOrLeft).add(this.bottomOrRight).add(divider);
@@ -942,7 +948,6 @@ private class Divider extends Container {
942948
private final Button btnExpand;
943949
private final Label dragHandle;
944950
int pressedX, pressedY, draggedX, draggedY;
945-
LayeredLayoutConstraint pressedPreferredConstraint;
946951
LayeredLayoutConstraint pressedConstraint;
947952
private boolean inDrag;
948953

@@ -1156,7 +1161,6 @@ public void pointerPressed(int x, int y) {
11561161
pressedX = x;
11571162
pressedY = y;
11581163
pressedConstraint = ((LayeredLayout) getLayout()).getOrCreateConstraint(this).copy();
1159-
pressedPreferredConstraint = preferredInset.copy();
11601164
inDrag = true;
11611165
pointerDragged(x, y);
11621166
}

CodenameOne/src/com/codename1/components/ToastBar.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ public class Status {
726726
/**
727727
* The start time of the process this status is tracking.
728728
*/
729-
private final long startTime;
730729
/**
731730
* This UIID that should be used to style the ToastBar text while this
732731
* message is being displayed.
@@ -777,7 +776,6 @@ public class Status {
777776
private boolean showProgressIndicator;
778777

779778
private Status() {
780-
startTime = System.currentTimeMillis();
781779
}
782780

783781
/**

CodenameOne/src/com/codename1/io/gzip/Deflate.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ final class Deflate {
141141
int pending; // nb of bytes in the pending buffer
142142
int wrap = 1;
143143
byte data_type; // UNKNOWN, BINARY or ASCII
144-
byte method; // STORED (for zip only) or DEFLATED
145144
int last_flush; // value of flush param for previous deflate call
146145
int w_size; // LZ77 window size (32K by default)
147146
int w_bits; // log2(w_size) (8..16)
@@ -1371,8 +1370,6 @@ private int deflateInit(int level, int method, int windowBits,
13711370
this.level = level;
13721371

13731372
this.strategy = strategy;
1374-
this.method = (byte) method;
1375-
13761373
return deflateReset();
13771374
}
13781375

CodenameOne/src/com/codename1/io/gzip/GZIPHeader.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,11 @@ public class GZIPHeader {
5858
public static final byte OS_UNKNOWN = (byte) 0xff;
5959

6060
boolean text = false;
61-
long time;
62-
int xflags;
6361
int os = 255;
6462
byte[] extra;
6563
byte[] name;
6664
byte[] comment;
67-
int hcrc;
6865
long crc;
69-
boolean done = false;
7066
long mtime = 0;
7167
private boolean fhcrc = false;
7268

CodenameOne/src/com/codename1/io/gzip/Inflate.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,9 @@ int inflate(int f) {
458458
} catch (Return e) {
459459
return e.r;
460460
}
461-
if (gheader != null)
462-
gheader.time = this.need;
461+
if (gheader != null) {
462+
gheader.setModifiedTime(this.need);
463+
}
463464
if ((flags & 0x0200) != 0) {
464465
checksum(4, this.need);
465466
}
@@ -471,7 +472,6 @@ int inflate(int f) {
471472
return e.r;
472473
}
473474
if (gheader != null) {
474-
gheader.xflags = ((int) this.need) & 0xff;
475475
gheader.os = (((int) this.need) >> 8) & 0xff;
476476
}
477477
if ((flags & 0x0200) != 0) {
@@ -555,9 +555,6 @@ int inflate(int f) {
555555
} catch (Return e) {
556556
return e.r;
557557
}
558-
if (gheader != null) {
559-
gheader.hcrc = (int) (this.need & 0xffff);
560-
}
561558
if (this.need != (z.adler.getValue() & 0xffffL)) {
562559
this.mode = BAD;
563560
z.msg = "header crc mismatch";

CodenameOne/src/com/codename1/io/gzip/Inflater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,6 @@ public int setDictionary(byte[] dictionary, int dictLength) {
160160
}
161161

162162
public boolean finished() {
163-
return istate.mode == 12 /*DONE*/;
163+
return finished;
164164
}
165165
}

0 commit comments

Comments
 (0)