highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
108 stars 54 forks source link

HashCodePlugin not working in 0.11.0 anymore #68

Closed chris922 closed 8 years ago

chris922 commented 8 years ago

I tried to get the HashCode plugin working (not the SimpleHashCode) and noticed, that changing a boolean (not Boolean) value doesn't lead to a new hashCode. After taking a look into the generated sourcecode I found out, that for boolean (probably all primitives) the generated code sets the valueSet argument always to true. Looking into the runtime libraries I saw that valueSet == true means, that the original value isn't considered when calculating the hashCode.

I rolled back to 0.10.0 and tested it again -> hashCode is working. So there might be a problem through this new valueSet attribute.

I assume that either this part might be wrong: HashCodePlugin.java:216

    final JExpression valueIsSet = (fieldAccessor.isAlwaysSet() || fieldAccessor
        .hasSetValue() == null) ? JExpr.TRUE
        : fieldAccessor.hasSetValue();

Or the handling of the valueSet attribute in DefaultHashCodeStrategy.java:155

Mistakenly I looked yesterday in the SimpleHashCode class and the valueSet attribute is calculated there differently. (SimpleHashCodePlugin.java:108) I already added a note there, the code there might be false, too.

If you need more information just ask :smiley:

highsource commented 8 years ago

Isn't it a duplicate for #67 which is already fixed? Could you please test the latest snapshot version?

highsource commented 8 years ago

Or could you PR the smallest possible project which reproduces this behaviour? Actually DefaultHashCodeStrategy.java:155 should no longer be called anyway, 297 should.

chris922 commented 8 years ago

It's working with the latest snapshot! Before I opened this issue I already used the latest snapshot to test.. but only for generating and not the snapshot runtime library. Sorry for that.

highsource commented 8 years ago

Released.