Skip to content

Commit 7e5e039

Browse files
committed
Initial work on improving spotless fixes
1 parent adebe5d commit 7e5e039

File tree

23 files changed

+143
-218
lines changed

23 files changed

+143
-218
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,18 @@ def main() -> None:
776776
"EQ_ALWAYS_FALSE",
777777
"SBSC_USE_STRINGBUFFER_CONCATENATION",
778778
"SIC_INNER_SHOULD_BE_STATIC",
779-
"EQ_DOESNT_OVERRIDE_EQUALS"
779+
"EQ_DOESNT_OVERRIDE_EQUALS",
780+
"CO_COMPARETO_INCORRECT_FLOATING",
781+
"DL_SYNCHRONIZATION_ON_SHARED_CONSTANT",
782+
"DLS_DEAD_LOCAL_STORE",
783+
"DM_NUMBER_CTOR",
784+
"DMI_INVOKING_TOSTRING_ON_ARRAY",
785+
"EC_NULL_ARG",
786+
"EC_UNRELATED_TYPES_USING_POINTER_EQUALITY",
787+
"EQ_GETCLASS_AND_CLASS_CONSTANT",
788+
"EQ_UNUSUAL",
789+
"ES_COMPARING_STRINGS_WITH_EQ",
790+
"FI_EMPTY"
780791
}
781792
violations = [
782793
f for f in spotbugs.findings

CodenameOne/src/com/codename1/capture/VideoCaptureConstraints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private String getMaxFileSizeString() {
190190

191191
@Override
192192
public boolean equals(Object obj) {
193-
if (obj.getClass() == VideoCaptureConstraints.class) {
193+
if (obj instanceof VideoCaptureConstraints) {
194194
VideoCaptureConstraints c = (VideoCaptureConstraints) obj;
195195
return c.preferredHeight == preferredHeight &&
196196
c.preferredWidth == preferredWidth &&

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -700,25 +700,25 @@ public static Object readObject(DataInputStream input) throws IOException {
700700
}
701701
String type = input.readUTF();
702702
if ("int".equals(type)) {
703-
return new Integer(input.readInt());
703+
return input.readInt();
704704
}
705705
if ("byte".equals(type)) {
706-
return new Byte(input.readByte());
706+
return input.readByte();
707707
}
708708
if ("short".equals(type)) {
709-
return new Short(input.readShort());
709+
return input.readShort();
710710
}
711711
if ("long".equals(type)) {
712-
return new Long(input.readLong());
712+
return input.readLong();
713713
}
714714
if ("float".equals(type)) {
715-
return new Float(input.readFloat());
715+
return input.readFloat();
716716
}
717717
if ("double".equals(type)) {
718-
return new Double(input.readDouble());
718+
return input.readDouble();
719719
}
720720
if ("bool".equals(type)) {
721-
return new Boolean(input.readBoolean());
721+
return input.readBoolean();
722722
}
723723
if ("String".equals(type)) {
724724
return input.readUTF();

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -357,82 +357,82 @@ protected void readResponse(InputStream input) throws IOException {
357357
return;
358358

359359
case TYPE_BYTE:
360-
returnValue = Byte.valueOf(dis.readByte());
360+
returnValue = dis.readByte();
361361
break;
362362

363363
case TYPE_CHAR:
364-
returnValue = new Character(dis.readChar());
364+
returnValue = dis.readChar();
365365
break;
366366

367367
case TYPE_SHORT:
368-
returnValue = Short.valueOf(dis.readShort());
368+
returnValue = dis.readShort();
369369
break;
370370

371371
case TYPE_INT:
372-
returnValue = Integer.valueOf(dis.readInt());
372+
returnValue = dis.readInt();
373373
break;
374374

375375
case TYPE_LONG:
376-
returnValue = Long.valueOf(dis.readLong());
376+
returnValue = dis.readLong();
377377
break;
378378

379379
case TYPE_DOUBLE:
380-
returnValue = new Double(dis.readDouble());
380+
returnValue = dis.readDouble();
381381
break;
382382

383383
case TYPE_FLOAT:
384-
returnValue = new Float(dis.readFloat());
384+
returnValue = dis.readFloat();
385385
break;
386386

387387
case TYPE_BOOLEAN:
388-
returnValue = Boolean.valueOf(dis.readBoolean());
388+
returnValue = dis.readBoolean();
389389
break;
390390

391391
case TYPE_BYTE_OBJECT:
392392
if (dis.readBoolean()) {
393-
returnValue = Byte.valueOf(dis.readByte());
393+
returnValue = dis.readByte();
394394
}
395395
break;
396396

397397
case TYPE_CHARACTER_OBJECT:
398398
if (dis.readBoolean()) {
399-
returnValue = new Character(dis.readChar());
399+
returnValue = dis.readChar();
400400
}
401401
break;
402402

403403
case TYPE_SHORT_OBJECT:
404404
if (dis.readBoolean()) {
405-
returnValue = Short.valueOf(dis.readShort());
405+
returnValue = dis.readShort();
406406
}
407407
break;
408408

409409
case TYPE_INTEGER_OBJECT:
410410
if (dis.readBoolean()) {
411-
returnValue = Integer.valueOf(dis.readInt());
411+
returnValue = dis.readInt();
412412
}
413413
break;
414414

415415
case TYPE_LONG_OBJECT:
416416
if (dis.readBoolean()) {
417-
returnValue = Long.valueOf(dis.readLong());
417+
returnValue = dis.readLong();
418418
}
419419
break;
420420

421421
case TYPE_DOUBLE_OBJECT:
422422
if (dis.readBoolean()) {
423-
returnValue = new Double(dis.readDouble());
423+
returnValue = dis.readDouble();
424424
}
425425
break;
426426

427427
case TYPE_FLOAT_OBJECT:
428428
if (dis.readBoolean()) {
429-
returnValue = new Float(dis.readFloat());
429+
returnValue = dis.readFloat();
430430
}
431431
break;
432432

433433
case TYPE_BOOLEAN_OBJECT:
434434
if (dis.readBoolean()) {
435-
returnValue = Boolean.valueOf(dis.readBoolean());
435+
returnValue = dis.readBoolean();
436436
}
437437
break;
438438

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void setComment(String comment) {
119119
try {
120120
this.comment = comment.getBytes("ISO-8859-1");
121121
} catch (UnsupportedEncodingException e) {
122-
throw new IllegalArgumentException("comment must be in ISO-8859-1 " + name);
122+
throw new IllegalArgumentException("comment must be in ISO-8859-1 " + comment);
123123
}
124124
}
125125

CodenameOne/src/com/codename1/payment/Purchase.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public abstract class Purchase {
5353
private static final String RECEIPTS_KEY = "CN1SubscriptionsData.dat";
5454
private static final String RECEIPTS_REFRESH_TIME_KEY = "CN1SubscriptionsDataRefreshTime.dat";
5555
private static final String PENDING_PURCHASE_KEY = "PendingPurchases.dat";
56+
private static final Object PENDING_PURCHASE_LOCK = new Object();
5657
private static final Object synchronizationLock = new Object();
5758
private static final Object receiptsLock = new Object();
5859
private static ReceiptStore receiptStore;
@@ -394,8 +395,9 @@ public void unsubscribe(String sku) {
394395
*
395396
* @return List of receipts that haven't been sent to the server.
396397
*/
398+
@SuppressWarnings("unchecked")
397399
public List<Receipt> getPendingPurchases() {
398-
synchronized (PENDING_PURCHASE_KEY) {
400+
synchronized (PENDING_PURCHASE_LOCK) {
399401
Storage s = Storage.getInstance();
400402
Util.register(new Receipt());
401403
if (s.exists(PENDING_PURCHASE_KEY)) {
@@ -409,10 +411,10 @@ public List<Receipt> getPendingPurchases() {
409411
/**
410412
* Adds a receipt to be pushed to the server.
411413
*
412-
* @param receipt
414+
* @param receipt the receipt
413415
*/
414416
private void addPendingPurchase(Receipt receipt) {
415-
synchronized (PENDING_PURCHASE_KEY) {
417+
synchronized (PENDING_PURCHASE_LOCK) {
416418
Storage s = Storage.getInstance();
417419
List<Receipt> pendingPurchases = getPendingPurchases();
418420
pendingPurchases.add(receipt);
@@ -423,11 +425,11 @@ private void addPendingPurchase(Receipt receipt) {
423425
/**
424426
* Removes a receipt from pending purchases.
425427
*
426-
* @param transactionId
427-
* @return
428+
* @param transactionId the transaction id
429+
* @return the removed receipt
428430
*/
429431
private Receipt removePendingPurchase(String transactionId) {
430-
synchronized (PENDING_PURCHASE_KEY) {
432+
synchronized (PENDING_PURCHASE_LOCK) {
431433
Storage s = Storage.getInstance();
432434
List<Receipt> pendingPurchases = getPendingPurchases();
433435
Receipt found = null;
@@ -490,7 +492,7 @@ public final void synchronizeReceipts(final long ifOlderThanMs, final SuccessCal
490492
syncInProgress = true;
491493
}
492494

493-
synchronized (PENDING_PURCHASE_KEY) {
495+
synchronized (PENDING_PURCHASE_LOCK) {
494496

495497
List<Receipt> pending = getPendingPurchases();
496498
if (!pending.isEmpty() && receiptStore != null) {
@@ -539,7 +541,6 @@ public void run() {
539541
synchronizeReceipts();
540542
}
541543
});
542-
543544
}
544545

545546
/**

CodenameOne/src/com/codename1/processing/HashtableContent.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import java.util.Vector;
3939

4040
/**
41-
* Internal class, do not use.
41+
* Internal class do not use.
4242
* <p>
4343
* A DOM accessor implementation for working with Map data.
4444
*
@@ -54,7 +54,7 @@ class MapContent implements StructuredContent {
5454
*
5555
* @param content parsed Map content
5656
*/
57-
public MapContent(Map content) {
57+
public MapContent(Map<?, ?> content) {
5858
this.root = content;
5959
}
6060

@@ -130,7 +130,9 @@ public int hashCode() {
130130
* @see java.lang.Object#equals(Object)
131131
*/
132132
public boolean equals(Object o) {
133-
return root.hashCode() == o.hashCode();
133+
return o instanceof MapContent &&
134+
(root == ((MapContent) o).root ||
135+
(root != null && root.equals(((MapContent) o).root)));
134136
}
135137

136138
/**

CodenameOne/src/com/codename1/processing/PrettyPrinter.java

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,26 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
5353
* @author Eric Coolman (2012-03 - derivative work from original Sun source).
5454
*/
5555
class PrettyPrinter {
56-
Map myHashMap;
56+
Map<?, ?> myHashMap;
5757

58-
private PrettyPrinter(Map h) {
58+
private PrettyPrinter(Map<?, ?> h) {
5959
this.myHashMap = h;
6060
}
6161

62-
public static String print(Map h) {
62+
public static String print(Map<?, ?> h) {
6363
return print(h, 2, 0);
6464
}
6565

66-
public static String print(List v) {
66+
public static String print(List<?> v) {
6767
return print(v, 2, 0);
6868
}
6969

70-
static String print(Map h, int indentFactor, int indent) {
70+
static String print(Map<?, ?> h, int indentFactor, int indent) {
7171
PrettyPrinter printer = new PrettyPrinter(h);
7272
return printer.toString(indentFactor, indent);
7373
}
7474

75-
static String print(List v, int indentFactor, int indent) {
75+
static String print(List<?> v, int indentFactor, int indent) {
7676
int len = v.size();
7777
if (len == 0) {
7878
return "[]";
@@ -120,7 +120,7 @@ static String print(List v, int indentFactor, int indent) {
120120
* with <code>}</code>&nbsp;<small>(right brace)</small>.
121121
*/
122122
static String valueToString(Object value, int indentFactor, int indent) {
123-
if (value == null || value.equals(null)) {
123+
if (value == null) {
124124
return "null";
125125
}
126126
try {
@@ -215,41 +215,6 @@ public static String quote(String string) {
215215
return sb.toString();
216216
}
217217

218-
/**
219-
* Make a JSON text of an Object value. If the object has an
220-
* value.toJSONString() method, then that method will be used to produce
221-
* the JSON text. The method is required to produce a strictly
222-
* conforming text. If the object does not contain a toJSONString
223-
* method (which is the most common case), then a text will be
224-
* produced by the rules.
225-
* <p>
226-
* Warning: This method assumes that the data structure is acyclical.
227-
*
228-
* @param value The value to be serialized.
229-
* @return a printable, displayable, transmittable
230-
* representation of the object, beginning
231-
* with <code>{</code>&nbsp;<small>(left brace)</small> and ending
232-
* with <code>}</code>&nbsp;<small>(right brace)</small>.
233-
*/
234-
static String valueToString(Object value) {
235-
if (value == null || value.equals(null)) {
236-
return "null";
237-
}
238-
if (value instanceof String) {
239-
return (String) value;
240-
}
241-
if (value instanceof Float || value instanceof Double ||
242-
value instanceof Byte || value instanceof Short ||
243-
value instanceof Integer || value instanceof Long) {
244-
return numberToString(value);
245-
}
246-
if (value instanceof Boolean || value instanceof Map ||
247-
value instanceof List) {
248-
return value.toString();
249-
}
250-
return quote(value.toString());
251-
}
252-
253218
static public String trimNumber(String s) {
254219
if (s.indexOf('.') > 0 && s.indexOf('e') < 0 && s.indexOf('E') < 0) {
255220
while (s.endsWith("0")) {
@@ -267,7 +232,6 @@ static public String trimNumber(String s) {
267232
*
268233
* @param n A Number
269234
* @return A String.
270-
* @throws JSONException If n is a non-finite number.
271235
*/
272236
static public String numberToString(Object n) {
273237
if (n == null) {
@@ -290,7 +254,7 @@ public int length() {
290254
*
291255
* @return An iterator of the keys.
292256
*/
293-
public Enumeration keys() {
257+
public Enumeration<?> keys() {
294258
return Collections.enumeration(this.myHashMap.keySet());
295259
}
296260

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public void actionPerformed(ActionEvent evt) {
130130
FaceBookAccess.getInstance().addResponseCodeListener(new ActionListener() {
131131

132132
public void actionPerformed(ActionEvent evt) {
133-
NetworkEvent ne = (NetworkEvent) evt;
134133
FaceBookAccess.getInstance().removeResponseCodeListener(this);
135134
progress.dispose();
136135
Dialog.show("Failed to Share", "for some reason sharing has failed, try again later.", "Ok", null);
@@ -163,8 +162,7 @@ public void actionPerformed(ActionEvent evt) {
163162
FaceBookAccess.getInstance().addResponseCodeListener(new ActionListener() {
164163

165164
public void actionPerformed(ActionEvent evt) {
166-
NetworkEvent ne = (NetworkEvent) evt;
167-
FaceBookAccess.getInstance().removeResponseCodeListener(this);
165+
FaceBookAccess.getInstance().removeResponseCodeListener(this);
168166
progress.dispose();
169167
Dialog.show("Failed to Share", "for some reason sharing has failed, try again later.", "Ok", null);
170168
finish();

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6531,7 +6531,10 @@ public boolean animate() {
65316531

65326532

65336533
Painter bgp = getStyle().getBgPainter();
6534-
boolean animateBackgroundB = bgp != null && bgp.getClass() != BGPainter.class && bgp instanceof Animation && (bgp != this) && ((Animation) bgp).animate();
6534+
boolean animateBackgroundB = bgp != null &&
6535+
bgp.getClass() != BGPainter.class &&
6536+
bgp instanceof Animation &&
6537+
((Animation) bgp).animate();
65356538
animateBackground = animateBackgroundB || animateBackground;
65366539

65376540
if (getUIManager().getLookAndFeel().isFadeScrollBar()) {

0 commit comments

Comments
 (0)