castor-data-binding / castor

http://castor-data-binding.github.io/castor/
35 stars 29 forks source link

Equals issue #52

Open jmborer opened 8 years ago

jmborer commented 8 years ago

Hello,

Long time ago, we used castor gen 1.3.1 and spotted an issue in the equals generation that we fixed and kept in our own version of castor-generator. Now we plan to upgrade to 1.4.1 and I checked if the issue is still there: yes it is.

In https://github.com/castor-data-binding/castor/blob/master/codegen/src/main/java/org/exolab/castor/builder/factory/SourceFactory.java

the block starting on line 1419:

 if (temp.getType().isPrimitive()) {
    jsc.add("if (this.");
    jsc.append(name);
    jsc.append(" != temp.");
    jsc.append(name);
    jsc.append(")");
  } else {

should be replaced by

               if (temp.getType().isPrimitive()) {
                    jsc.add("if (this.");
                    jsc.append(name);
                    jsc.append(" != temp.");
                    jsc.append(name);
                    jsc.append(")");
                    jsc.indent();
                    jsc.add("return false;");
                    jsc.unindent();
                } else {

And on line 1570 right after the

       if (state.getFieldInfoForChoice() != null
                && name.equals(state.getFieldInfoForChoice().getName())) {
            continue;
        }

block, it should be added

        if (name.startsWith("enumConstants")) {
            continue;
        }

Hope it helps

wguttmn commented 8 years ago

Mind putting this into a pull request ? And adding a test case that allows you to replay the problem at hand would be of great benefit as well, so that it could be added to Castor's test suite.

jmborer commented 8 years ago

We fixed this in 2011 on version 1.3.1. Unfortunately, I have forgotten how to reproduce the issue. Apparently equality of elements with enums seems to work properly now (1.4.1). If I find the solution, I will publish the test case.

wguttmn commented 8 years ago

Any more findings ?