Skip to content

Commit adebe5d

Browse files
Fix SpotBugs EQ_DOESNT_OVERRIDE_EQUALS violations (#4373)
* Fix SpotBugs EQ_DOESNT_OVERRIDE_EQUALS violations Implemented equals() and hashCode() overrides for 24 classes flagged by SpotBugs. Updated quality report script to enforce EQ_DOESNT_OVERRIDE_EQUALS. * Fix SpotBugs EQ_DOESNT_OVERRIDE_EQUALS violations Refactored anonymous ConnectionRequest in CloudImageProperty to a named inner class to implement equals/hashCode. Fixed equality check in GZConnectionRequest. Corrected duplicate Javadoc in InnerActive. Updated quality report script to enforce EQ_DOESNT_OVERRIDE_EQUALS. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent d905b7d commit adebe5d

25 files changed

+2597
-1833
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,8 @@ def main() -> None:
775775
"EC_UNRELATED_TYPES",
776776
"EQ_ALWAYS_FALSE",
777777
"SBSC_USE_STRINGBUFFER_CONCATENATION",
778-
"SIC_INNER_SHOULD_BE_STATIC"
778+
"SIC_INNER_SHOULD_BE_STATIC",
779+
"EQ_DOESNT_OVERRIDE_EQUALS"
779780
}
780781
violations = [
781782
f for f in spotbugs.findings

CodenameOne/src/com/codename1/ads/InnerActive.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,50 @@ public void initService(Ads ads) {
156156
setDuplicateSupported(true);
157157
}
158158

159+
/**
160+
* {@inheritDoc}
161+
*/
162+
public boolean equals(Object o) {
163+
if (this == o) {
164+
return true;
165+
}
166+
if (o == null || getClass() != o.getClass()) {
167+
return false;
168+
}
169+
if (!super.equals(o)) {
170+
return false;
171+
}
172+
173+
InnerActive that = (InnerActive) o;
174+
175+
if (po != that.po) {
176+
return false;
177+
}
178+
if (banner != that.banner) {
179+
return false;
180+
}
181+
if (os != null ? !os.equals(that.os) : that.os != null) {
182+
return false;
183+
}
184+
if (hid != null ? !hid.equals(that.hid) : that.hid != null) {
185+
return false;
186+
}
187+
188+
return true;
189+
}
190+
191+
/**
192+
* {@inheritDoc}
193+
*/
194+
public int hashCode() {
195+
int result = super.hashCode();
196+
result = 31 * result + po;
197+
result = 31 * result + (os != null ? os.hashCode() : 0);
198+
result = 31 * result + (hid != null ? hid.hashCode() : 0);
199+
result = 31 * result + (banner ? 1 : 0);
200+
return result;
201+
}
202+
159203
/**
160204
* {@inheritDoc}
161205
*/

CodenameOne/src/com/codename1/cloud/CloudImageProperty.java

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,38 @@ private CacheMap getCache() {
6868
return cloudImageCache;
6969
}
7070

71+
/**
72+
* {@inheritDoc}
73+
*/
74+
public boolean equals(Object o) {
75+
if (this == o) {
76+
return true;
77+
}
78+
if (o == null || getClass() != o.getClass()) {
79+
return false;
80+
}
81+
82+
CloudImageProperty that = (CloudImageProperty) o;
83+
84+
if (idProperty != null ? !idProperty.equals(that.idProperty) : that.idProperty != null) {
85+
return false;
86+
}
87+
if (placeholderImage != null ? !placeholderImage.equals(that.placeholderImage) : that.placeholderImage != null) {
88+
return false;
89+
}
90+
91+
return true;
92+
}
93+
94+
/**
95+
* {@inheritDoc}
96+
*/
97+
public int hashCode() {
98+
int result = idProperty != null ? idProperty.hashCode() : 0;
99+
result = 31 * result + (placeholderImage != null ? placeholderImage.hashCode() : 0);
100+
return result;
101+
}
102+
71103
/**
72104
* {@inheritDoc}
73105
*/
@@ -84,27 +116,7 @@ public Object propertyValue(CloudObject obj, String propertyName) {
84116
}
85117
final ReplaceableImage rp = ReplaceableImage.create(placeholderImage);
86118
inProgress.put(key, rp);
87-
ConnectionRequest cr = new ConnectionRequest() {
88-
private EncodedImage e;
89-
90-
protected void readResponse(InputStream input) throws IOException {
91-
e = EncodedImage.create(input);
92-
if (e.getWidth() != placeholderImage.getWidth() || e.getHeight() != placeholderImage.getHeight()) {
93-
ImageIO io = ImageIO.getImageIO();
94-
if (io != null) {
95-
ByteArrayOutputStream bo = new ByteArrayOutputStream();
96-
io.save(new ByteArrayInputStream(e.getImageData()), bo, ImageIO.FORMAT_JPEG, placeholderImage.getWidth(), placeholderImage.getHeight(), 0.9f);
97-
e = EncodedImage.create(bo.toByteArray());
98-
}
99-
}
100-
}
101-
102-
protected void postResponse() {
103-
rp.replace(e);
104-
getCache().put(key, e);
105-
inProgress.remove(key);
106-
}
107-
};
119+
ConnectionRequest cr = new CloudImageRequest(rp, key);
108120
cr.setPost(false);
109121
cr.setUrl(CloudStorage.getInstance().getUrlForCloudFileId(key));
110122
NetworkManager.getInstance().addToQueue(cr);
@@ -113,4 +125,47 @@ protected void postResponse() {
113125
return image;
114126
}
115127

128+
private class CloudImageRequest extends ConnectionRequest {
129+
private EncodedImage e;
130+
private final ReplaceableImage rp;
131+
private final String key;
132+
133+
public CloudImageRequest(ReplaceableImage rp, String key) {
134+
this.rp = rp;
135+
this.key = key;
136+
}
137+
138+
protected void readResponse(InputStream input) throws IOException {
139+
e = EncodedImage.create(input);
140+
if (e.getWidth() != placeholderImage.getWidth() || e.getHeight() != placeholderImage.getHeight()) {
141+
ImageIO io = ImageIO.getImageIO();
142+
if (io != null) {
143+
ByteArrayOutputStream bo = new ByteArrayOutputStream();
144+
io.save(new ByteArrayInputStream(e.getImageData()), bo, ImageIO.FORMAT_JPEG, placeholderImage.getWidth(), placeholderImage.getHeight(), 0.9f);
145+
e = EncodedImage.create(bo.toByteArray());
146+
}
147+
}
148+
}
149+
150+
protected void postResponse() {
151+
rp.replace(e);
152+
getCache().put(key, e);
153+
inProgress.remove(key);
154+
}
155+
156+
/**
157+
* {@inheritDoc}
158+
*/
159+
public boolean equals(Object o) {
160+
return super.equals(o);
161+
}
162+
163+
/**
164+
* {@inheritDoc}
165+
*/
166+
public int hashCode() {
167+
return super.hashCode();
168+
}
169+
}
170+
116171
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,29 @@ public BackCommand(Form sourceForm) {
477477
public void actionPerformed(ActionEvent ev) {
478478
sourceForm.showBack();
479479
}
480+
481+
/**
482+
* {@inheritDoc}
483+
*/
484+
public boolean equals(Object o) {
485+
if (this == o) {
486+
return true;
487+
}
488+
if (o == null || getClass() != o.getClass()) {
489+
return false;
490+
}
491+
if (!super.equals(o)) {
492+
return false;
493+
}
494+
return true;
495+
}
496+
497+
/**
498+
* {@inheritDoc}
499+
*/
500+
public int hashCode() {
501+
return super.hashCode();
502+
}
480503
}
481504

482505
class EventHandler implements ActionListener {

CodenameOne/src/com/codename1/facebook/Album.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,24 @@ private void init(Hashtable toCopy) {
178178
created_time = (String) toCopy.get("created_time");
179179
updated_time = (String) toCopy.get("updated_time");
180180
}
181+
182+
/**
183+
* {@inheritDoc}
184+
*/
185+
public boolean equals(Object o) {
186+
if (this == o) {
187+
return true;
188+
}
189+
if (o == null || getClass() != o.getClass()) {
190+
return false;
191+
}
192+
return super.equals(o);
193+
}
194+
195+
/**
196+
* {@inheritDoc}
197+
*/
198+
public int hashCode() {
199+
return super.hashCode();
200+
}
181201
}

CodenameOne/src/com/codename1/facebook/FacebookRESTService.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,48 @@ public void longToken(long tok) {
318318
public void booleanToken(boolean tok) {
319319
}
320320

321+
/**
322+
* {@inheritDoc}
323+
*/
324+
public boolean equals(Object o) {
325+
if (this == o) {
326+
return true;
327+
}
328+
if (o == null || getClass() != o.getClass()) {
329+
return false;
330+
}
331+
if (!super.equals(o)) {
332+
return false;
333+
}
334+
335+
FacebookRESTService that = (FacebookRESTService) o;
336+
337+
if (responseOffset != that.responseOffset) {
338+
return false;
339+
}
340+
if (connectionType != null ? !connectionType.equals(that.connectionType) : that.connectionType != null) {
341+
return false;
342+
}
343+
if (imageKey != null ? !imageKey.equals(that.imageKey) : that.imageKey != null) {
344+
return false;
345+
}
346+
if (root != null ? !root.equals(that.root) : that.root != null) {
347+
return false;
348+
}
349+
350+
return true;
351+
}
352+
353+
/**
354+
* {@inheritDoc}
355+
*/
356+
public int hashCode() {
357+
int result = super.hashCode();
358+
result = 31 * result + (connectionType != null ? connectionType.hashCode() : 0);
359+
result = 31 * result + responseOffset;
360+
result = 31 * result + (imageKey != null ? imageKey.hashCode() : 0);
361+
result = 31 * result + (root != null ? root.hashCode() : 0);
362+
return result;
363+
}
364+
321365
}

CodenameOne/src/com/codename1/facebook/Page.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,24 @@ private void init(Hashtable toCopy) {
151151
coverLink = (String) cover.get("source");
152152
}
153153
}
154+
155+
/**
156+
* {@inheritDoc}
157+
*/
158+
public boolean equals(Object o) {
159+
if (this == o) {
160+
return true;
161+
}
162+
if (o == null || getClass() != o.getClass()) {
163+
return false;
164+
}
165+
return super.equals(o);
166+
}
167+
168+
/**
169+
* {@inheritDoc}
170+
*/
171+
public int hashCode() {
172+
return super.hashCode();
173+
}
154174
}

CodenameOne/src/com/codename1/facebook/Photo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,24 @@ private void init(Hashtable toCopy) {
220220
}
221221

222222
}
223+
224+
/**
225+
* {@inheritDoc}
226+
*/
227+
public boolean equals(Object o) {
228+
if (this == o) {
229+
return true;
230+
}
231+
if (o == null || getClass() != o.getClass()) {
232+
return false;
233+
}
234+
return super.equals(o);
235+
}
236+
237+
/**
238+
* {@inheritDoc}
239+
*/
240+
public int hashCode() {
241+
return super.hashCode();
242+
}
223243
}

CodenameOne/src/com/codename1/facebook/Post.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,24 @@ private void init(Hashtable toCopy) {
225225
}
226226
}
227227
}
228+
229+
/**
230+
* {@inheritDoc}
231+
*/
232+
public boolean equals(Object o) {
233+
if (this == o) {
234+
return true;
235+
}
236+
if (o == null || getClass() != o.getClass()) {
237+
return false;
238+
}
239+
return super.equals(o);
240+
}
241+
242+
/**
243+
* {@inheritDoc}
244+
*/
245+
public int hashCode() {
246+
return super.hashCode();
247+
}
228248
}

CodenameOne/src/com/codename1/facebook/User.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,24 @@ private void init(Hashtable toCopy) {
245245
}
246246
}
247247

248+
/**
249+
* {@inheritDoc}
250+
*/
251+
public boolean equals(Object o) {
252+
if (this == o) {
253+
return true;
254+
}
255+
if (o == null || getClass() != o.getClass()) {
256+
return false;
257+
}
258+
return super.equals(o);
259+
}
260+
261+
/**
262+
* {@inheritDoc}
263+
*/
264+
public int hashCode() {
265+
return super.hashCode();
266+
}
267+
248268
}

0 commit comments

Comments
 (0)