<div dir="ltr">Adding a little bit extra on top of that: I believe that if Java ever wants to go down this route, then it should first develop the notion of "nothrows" (or maybe even a strong constraint on what is allowed to be thrown), and then on top of that the flow analysis could be enhanced. I'm not saying I'm eager for this to happen but I think that would be the bare minimum before this issue should be considered to be fixed.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com">attila.kelemen85@gmail.com</a>> ezt írta (időpont: 2024. júl. 13., Szo, 13:38):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I guess the main difference in our thinking is that I value the complexity of the JLS more. The informal rule you are talking about (i.e., assigned exactly once) might appear to be simple but it is in reality impossible to prove completely and there is no end to complicating the formal rule. I mean, I showed a simple complication in my previous email already but let's go further. Why shouldn't the following work then?</div><div><br></div><div>```</div><div>final int x;<br>int i = 0;<br>try {<br> x = func();<br> i++;<br>} catch (Exception e) {<br> x = -1;<br>}<br></div><div>```</div><div><br></div><div>or even</div><div><br></div><div>```</div><div>int end = 1;<br>final int x;<br>for (int i = 0; i < end; i++) {<br> x = 5;<br>}<br></div><div>```</div><div><br></div><div>All of the above would be equally possible for the compiler to deduce to be correct. Complicating the formal rule matters a lot for the language in my opinion. And of course, you could complicate the language but then I would expect some major gain from it. What do we gain here? That we can add the `final` keyword to a local variable declaration? That doesn't seem very valuable to me (assuming the variable capturing rule is relaxed as I wrote).</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Olexandr Rotan <<a href="mailto:rotanolexandr842@gmail.com" target="_blank">rotanolexandr842@gmail.com</a>> ezt írta (időpont: 2024. júl. 13., Szo, 13:16):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">It would be good to fix what you are saying. However, I don't agree that this enhancement would introduce any new rule. Rule for final variables and fields is one and only one in this context: it must be initialized once. This fix would just make enforcement of this rule more precise by modifying existing compiler rules that currently don't let through code that is intuitively and factually correct, but falls into a blind spot of specifications. Of course, JLS defines a set of rules on how to determine whether the value was previously assigned or not, and, strictly speaking, current behaviour is the right one. However, JLS here fails to let through valid code from, lets say, a logical point of view. So, actually, no one introduces new rules to the compiler. In fact, this fix would remove exception from the rules that are semantically applied to final variables.</div>
</blockquote></div></div>
</blockquote></div>