Fix #1424 - redundant null check in JDK maps - #1425
Conversation
|
Thank you for the PR! but we need to investigate why those checks are there in the first place, there's a chance it was some compatibility fix, or it can be, indeed, just a strange mistake |
|
@elucash Did you already have time to look into this? We use Immutables in various projects and we cannot update Immutables in them if they use maps because Spotbugs complains about it. And our build pipeline is configured to fail if Spotbugs finds any errors. |
|
I'll get back to it asap (1-2 days), sorry for delay |
|
No worries, thank you |
|
Ok, I guess I figured it out. So the older merged PR tried to improve message when a value is |
|
I updated the PR with the fix proposed by you. I now get the idea behind the initial change. However, if you have concerns about the performance impact, my solution still is worse than before. The string concationation is now only done if the value is null but the But honestly, I think the performance impact of the string concatination and the extra method call is neglectable. The Java Language Specification says the following about string concationation: In the end I think there is a trade-off between performance and clean code. In my opinion, the negative impact of my initial proposal is neglectable and the generated code does indeed look strange without having the background knowledge you provided here. I would prefer my inital proposal because it looks cleaner but the final decision is up to you. I just wanted to share my opinion on that topic. If you think that my second proposal meets your requirements, I'm fine with that, too. Spotbugs does not complain about that construct. |
|
Thank you for updating the PR! As performance goes, I'll tell that, of course, we all can be wrong, speculate too much without actually checking with sophisticated tools (like JMH etc), but, probably, "average performance nitpicker" will expect some tricks from that code. In particular String x = "a" + b + "c" + d;
// gets "desugared" into
String x = new StringBuilder().append("a").append(b).append("c").append(d).toString();
// (i.e. Java 8 compiler would emit bytecode equivalent to the java line above)
// But I've never seen (may be wrong, but..) about anything like this
String x = "";
for (int i : codesArray) x += ":" + i;
// being turned into below, so people would manually turn it into
StringBuilder xb = new StringBuilder();
for (int i : codesArray) xb.append(":").append(i);
String x = xb.toString();And the last example is irrelevant in our case, as we need concatenated value on each iteration, so if |
Fix #1424