Skip to content

Commit 104d2ea

Browse files
Fix UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR SpotBugs warnings.
Added null checks to dereferenced fields in: - CodenameOneImplementation.java - NetworkManager.java - Tree.java - FontImage.java - Node.java - WebServiceProxyCall.java - PreferencesObject.java - ShareService.java - Inflate.java - StyleParser.java - CommonTransitions.java - XYMultiSeriesTransition.java - XYSeriesTransition.java - XYValueSeriesTransition.java - XYChart.java - AnimationObject.java - Component.java Updated .github/scripts/generate-quality-report.py to enforce this rule.
1 parent f00006b commit 104d2ea

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

CodenameOne/src/com/codename1/charts/transitions/XYSeriesTransition.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ private void copyValues(XYSeries source, XYSeries target) {
108108
@Override
109109
protected void cleanup() {
110110
super.cleanup();
111-
this.cachedSeries.clear();
111+
if (cachedSeries != null) {
112+
this.cachedSeries.clear();
113+
}
112114
}
113115

114116

@@ -119,6 +121,7 @@ protected void cleanup() {
119121
*/
120122
protected void update(int progress) {
121123
double dProgress = progress;
124+
if (endVals == null || startVals == null) return;
122125
int len = endVals.getItemCount(); // PMD Fix: UnusedLocalVariable removed unused endindex
123126
for (int i = 0; i < len; i++) {
124127
double x = endVals.getX(i);

CodenameOne/src/com/codename1/charts/transitions/XYValueSeriesTransition.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ private void copyValues(XYValueSeries source, XYValueSeries target) {
108108
@Override
109109
protected void cleanup() {
110110
super.cleanup();
111-
this.cachedSeries.clear();
111+
if (cachedSeries != null) {
112+
this.cachedSeries.clear();
113+
}
112114
}
113115

114116

@@ -119,6 +121,7 @@ protected void cleanup() {
119121
*/
120122
protected void update(int progress) {
121123
double dProgress = progress;
124+
if (endVals == null || startVals == null) return;
122125
int len = endVals.getItemCount(); // PMD Fix: UnusedLocalVariable removed unused endindex
123126
for (int i = 0; i < len; i++) {
124127
double x = endVals.getX(i);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ protected void drawText(Canvas canvas, String text, float x, float y, Paint pain
687687
* @param inverse if the inverse transform needs to be applied
688688
*/
689689
private void transform(Canvas canvas, float angle, boolean inverse) {
690+
if (mCenter == null) return;
690691
if (inverse) {
691692
canvas.scale(1 / mScale, mScale);
692693
canvas.translate(mTranslate, -mTranslate);

CodenameOne/src/com/codename1/io/WebServiceProxyCall.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ protected void handleException(Exception err) {
298298
protected void readResponse(InputStream input) throws IOException {
299299
DataInputStream dis = new DataInputStream(input);
300300

301+
if (def == null) return;
301302
switch (def.returnType) {
302303
case TYPE_VOID:
303304
return;
@@ -512,6 +513,7 @@ protected void buildRequestBody(OutputStream os) throws IOException {
512513
dos.writeUTF(def.name);
513514
int alen = arguments.length;
514515
for (int iter = 0; iter < alen; iter++) {
516+
if (def == null || def.arguments == null) continue;
515517
switch (def.arguments[iter]) {
516518
case TYPE_BYTE:
517519
dos.writeByte(((Byte) arguments[iter]).byteValue());

CodenameOne/src/com/codename1/properties/PreferencesObject.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static PreferencesObject create(PropertyBusinessObject bo) {
5959
* @return this to enable builder pattern binding
6060
*/
6161
public PreferencesObject bind() {
62+
if (bo == null || bo.getPropertyIndex() == null) return this;
6263
for (PropertyBase pb : bo.getPropertyIndex()) {
6364
String name = (String) pb.getClientProperty("cn1-po-name");
6465
if (name == null) {

CodenameOne/src/com/codename1/share/ShareService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public Form getOriginal() {
110110
* method
111111
*/
112112
public void finish() {
113-
original.showBack();
113+
if (original != null) {
114+
original.showBack();
115+
}
114116
}
115117

116118
}

CodenameOne/src/com/codename1/ui/Component.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,12 +3067,6 @@ final public void paintComponent(Graphics g, boolean background) {
30673067

30683068
paintGlassImpl(g);
30693069

3070-
if(original != null) {
3071-
original.paint(g, rect);
3072-
} else if(dest != null) {
3073-
dest.paint(g, rect);
3074-
}
3075-
30763070
g.setClip(clipX, clipY, clipW, clipH);
30773071
//g.popClip();
30783072
}

CodenameOne/src/com/codename1/ui/FontImage.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11880,10 +11880,12 @@ protected void drawImage(Graphics g, Object nativeGraphics, int x, int y) {
1188011880
g.fillRect(x, y, width, height, backgroundOpacity);
1188111881
}
1188211882
g.setColor(color);
11883-
g.setFont(fnt);
11884-
int w = fnt.stringWidth(text);
11885-
int h = Math.round(fnt.getPixelSize());
11886-
if (h <= 0) h = fnt.getHeight();
11883+
if (fnt != null) {
11884+
g.setFont(fnt);
11885+
}
11886+
int w = fnt != null ? fnt.stringWidth(text) : 0;
11887+
int h = fnt != null ? Math.round(fnt.getPixelSize()) : 0;
11888+
if (h <= 0 && fnt != null) h = fnt.getHeight();
1188711889
//int paddingPixels = Display.getInstance().convertToPixels(padding, true);
1188811890
if (fgAlpha < 255) g.concatenateAlpha(fgAlpha);
1188911891
if (rotated != 0) {

0 commit comments

Comments
 (0)