Skip to content

Commit c5b1d0c

Browse files
authored
Fixed some of the problems in the code (#4128)
* Fixed some of the problems in the code * Fixed CI
1 parent 7d9676f commit c5b1d0c

27 files changed

+202
-170
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public byte[] getImageData() {
129129
public void run() {
130130
InputStream i = null;
131131
try {
132+
if (!FileSystemStorage.getInstance().exists(fileName)) {
133+
Log.p(fileName + " doesn't exist");
134+
return;
135+
}
132136
final byte[] imageDataLocal = new byte[(int) FileSystemStorage.getInstance().getLength(fileName)];
133137
i = FileSystemStorage.getInstance().openInputStream(fileName);
134138
Util.readFully(i, imageDataLocal);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public class StorageImageAsync extends EncodedImage {
4242
private final String fileName;
4343
private boolean changePending;
4444
private boolean imageCreated;
45-
private byte[] imageData;
45+
private volatile byte[] imageData;
4646
private final Image placeholderImage;
47-
private boolean queued;
47+
private volatile boolean queued;
4848

4949
private StorageImageAsync(String fileName, Image placeholderImage) {
5050
super(placeholderImage.getWidth(), placeholderImage.getHeight());
@@ -111,12 +111,12 @@ public void run() {
111111
resetCache();
112112
changePending = true;
113113
imageCreated = false;
114+
queued = false;
114115
}
115116
});
116117
} catch (Throwable ex) {
117118
Log.e(ex);
118119
} finally {
119-
queued = false;
120120
Util.cleanup(i);
121121
}
122122
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ private Cookie parseCookieHeader(String h) {
13161316
}
13171317

13181318
if (Util.getImplementation().getURLPath(url).indexOf(path) != 0) { //if (!hc.getHost().endsWith(domain)) {
1319-
System.out.println("Warning: Cookie tried to set to another path");
1319+
Log.p("Warning: Cookie tried to set to another path");
13201320
c.setPath(path);
13211321
} else {
13221322
// Don't set the path explicitly

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public static void parse(Reader i, JSONParseCallback callback) throws IOExceptio
214214
} catch (NumberFormatException err) {
215215
// problem in parsing the u notation!
216216
Log.e(err);
217-
System.out.println("Error in parsing \\u" + unicode);
217+
Log.p("Error in parsing \\u" + unicode);
218218
}
219219
} else {
220220
switch (c) {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.codename1.io;
2525

2626
import com.codename1.compat.java.util.Objects;
27+
import com.codename1.impl.CodenameOneImplementation;
2728
import com.codename1.impl.CodenameOneThread;
2829
import com.codename1.ui.Command;
2930
import com.codename1.ui.Dialog;
@@ -165,7 +166,7 @@ protected void readResponse(java.io.InputStream input) throws java.io.IOExceptio
165166
}
166167

167168
protected void handleErrorResponseCode(int code, String message) {
168-
System.out.print("Error in sending log to server: " + code + " " + message);
169+
Log.p("Error in sending log to server: " + code + " " + message);
169170
}
170171

171172
protected void handleException(Exception err) {
@@ -480,7 +481,12 @@ protected void print(String text, int level) {
480481
}
481482
logDirty = true;
482483
text = getThreadAndTimeStamp() + " - " + text;
483-
Util.getImplementation().systemOut(text);
484+
CodenameOneImplementation impl = Util.getImplementation();
485+
if(impl != null) {
486+
impl.systemOut(text);
487+
} else {
488+
System.out.println(text);
489+
}
484490
try {
485491
synchronized (this) {
486492
Writer w = getWriter();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ void addToQueue(@Async.Schedule ConnectionRequest request, boolean retry) {
565565
if (!retry) {
566566
if (!request.isDuplicateSupported()) {
567567
if (pending.contains(request)) {
568-
System.out.println("Duplicate entry in the queue: " + request.getClass().getName() + ": " + request);
568+
Log.p("Duplicate entry in the queue: " + request.getClass().getName() + ": " + request);
569569
return;
570570
}
571571
ConnectionRequest currentRequest = networkThreads[0].getCurrentRequest();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.codename1.io;
2626

27+
import com.codename1.impl.CodenameOneImplementation;
2728
import com.codename1.util.StringUtil;
2829

2930
import java.io.DataInputStream;
@@ -196,7 +197,8 @@ public InputStream createInputStream(String name) throws IOException {
196197
*/
197198
public boolean exists(String name) {
198199
name = fixFileName(name);
199-
return Util.getImplementation().storageFileExists(name);
200+
CodenameOneImplementation implementation = Util.getImplementation();
201+
return implementation != null && implementation.storageFileExists(name);
200202
}
201203

202204
/**

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.codename1.impl.VirtualKeyboardInterface;
3636
import com.codename1.io.Log;
3737
import com.codename1.io.Preferences;
38+
import com.codename1.io.Util;
3839
import com.codename1.l10n.L10NManager;
3940
import com.codename1.location.LocationManager;
4041
import com.codename1.media.Media;
@@ -845,17 +846,12 @@ public void run() {
845846
}
846847
backgroundTasks.remove(0);
847848
}
848-
//preent a runtime exception to crash the
849-
//backgroundThread
850849
try {
851850
executeBackgroundTaskRunnable(nextTask);
852851
} catch (Throwable e) {
853852
Log.e(e);
854853
}
855-
try {
856-
Thread.sleep(10);
857-
} catch (InterruptedException ex) {
858-
}
854+
Util.sleep(10);
859855
}
860856
}
861857
}, "Task Thread");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public static EncodedImage create(byte[] data, int width, int height, boolean op
265265
public static EncodedImage create(InputStream i) throws IOException {
266266
byte[] buffer = Util.readInputStream(i);
267267
if (buffer.length > 200000) {
268-
System.out.println("Warning: loading large images using EncodedImage.create(InputStream) might lead to memory issues, try using EncodedImage.create(InputStream, int)");
268+
Log.p("Warning: loading large images using EncodedImage.create(InputStream) might lead to memory issues, try using EncodedImage.create(InputStream, int)");
269269
}
270270
return new EncodedImage(new byte[][]{buffer});
271271
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,6 @@ public Span triggerSelectionAt(TextSelection sel, int x, int y) {
15231523
break;
15241524
}
15251525
}
1526-
System.out.println("Text is [" + getText().substring(startPos, endPos) + "]");
15271526
return span.subspan(startPos, endPos);
15281527
}
15291528

0 commit comments

Comments
 (0)