--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/0345bb9b-6543-4fb9-8922-618adea1e678%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[…] you're in for trouble if you are serializing such fields.
This is why the rule detects when you are actually serializing value based class like LocalDate.
[…] we recommend you to not serialize this field by making it transient. If you really need to get that info serialized, up to you to come with a solution to that issue (custom write, using a type which is not value based,, etc.).
The issue is more complex than that. The issue is that when you have two LocalDate objects, ld1 and ld2, then (ld1 == ld2) is undefined.
That is, if it is perfectly permissible for (ld1.equals(ld2) == true) and (ld1 != ld2 == true). This would break serialisation horribly since two different objects could be mistakenly assumed to be the same. Or it might work. Or it might work sometimes, but not others. That's the great thing about undefined.
Am Montag, 5. September 2016 11:11:00 UTC+2 schrieb Paul Wagland:The issue is more complex than that. The issue is that when you have two LocalDate objects, ld1 and ld2, then (ld1 == ld2) is undefined.
Rather, will be undefined in the future. For Java 8, there actually are no value-types. You might well consider not applying any value-base-type rule to code with language-level 8. On the other hand, it is of course great to be warned of possible issues long ahead.
That is, if it is perfectly permissible for (ld1.equals(ld2) == true) and (ld1 != ld2 == true). This would break serialisation horribly since two different objects could be mistakenly assumed to be the same. Or it might work. Or it might work sometimes, but not others. That's the great thing about undefined.
I really feel stupid now – but how will it break serialization? Two different LocalDate objects that happen to represent the same day may end up unified during serialization or later during deserialization; what does it matter? Or, two references to the same instance may actually come out of the process as two different instances; but what does it matter?
[…] is that if you have an Optional you might not be able to re-instantiate it to be of the right type.
[…] you could have two Optional values that represent very different things ending up getting combined, since Serialization might mistakenly think that they are the same. Imagine, for example, one Optional that was "null", and the other that held a real value. If these two got 'combined', you would almost certainly not be happy!
I’m going to raise an issue in the bug tracker then, since I’m still convinced that this borders on a false positive. At the very least this rule should not be enabled in the “Sonar Way”, since it actually promotes making your code less stable.
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/66ce11b1-f706-4cd7-9007-f1a16d6f3e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Michael,This is not a false positive. Serializing a value type _will_ (because JVM 8 won't do anything as of today) break serialization as it will break its contract.
Have a look at this answer of B.Goetz on the valhalla ML : http://mail.openjdk.java.net/pipermail/valhalla-dev/2015-February/001043.html to get a better understanding of why. It completes its answer on stackoverflow : it all boils down to serialized graph topology.
I admit that as of today it is a bit of a theoretical problem, however you can't state it is a false positive when the rue actually enforce the documentation recommendation.
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/7ba30ade-40bd-4669-9572-2e2e4d8d499c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Senior Developer