Bug 500330

Summary: equals generation with additional option
Product: [Eclipse Project] JDT Reporter: Fernando Boaglio <fernando>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: stephan.herrmann
Version: 4.7   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

Description Fernando Boaglio CLA 2016-08-26 08:48:53 EDT

    
Comment 1 Fernando Boaglio CLA 2016-08-26 08:56:26 EDT
I would like to have an option in equals generation to consider empty Lists or Hashs the same thing as null lists/hashs. 

Equals example (for a "tags" List) today:

if (tags == null) {
 if (other.tags != null) { return false; }
} else if (!tags.equals(other.tags)) { return false; }

Equals example (for a "tags" List) with consider [empty list] == [null list] option enabled:

if ( (other.tags == null || other.tags.size() == 0) && (tags == null || tags.size() == 0)) {
return true;
} else if (tags == null || tags.size() == 0) {
if (other.tags != null || other.tags.size() > 0) { return false; }
} else if (!tags.equals(other.tags)) { return false; }


Thank you.
Comment 2 Stephan Herrmann CLA 2016-08-26 11:39:03 EDT
I personally am not sure, that's a coding style that JDT wants to actively support. Wouldn't consistently using empty lists instead of null make for much simpler and safer code?
Comment 3 Fernando Boaglio CLA 2016-08-26 15:37:47 EDT
You are right, but these objects come from ReST services and sometimes they are null or empty.
From the business point of view, it is the same thing; that´s why I ask for this feature.