Incorrect "variable might not have been initialized"

D

Dale King

Chris said:
I'm getting confused, but I don't /think/ I agree. I think you are considering
the assignment
retain = xxxxx && yyyyy
to be "caught" by 16.1.7 (I agree that it is an expression of type boolean,
etc), whereas my breakdown considers it to be caught by 16.1.8. Having applied
16.1.8, the remainder is reduced to an "expression of type boolean", but one
which /does/ have an &&.

There seems to be an ambiguity in the JLS here in that two rules apply, but
lead to different results depending on which one is used.

Both rules do apply. You can logically apply the rules in the order I
applied them, but there is no way to apply them in the reverse order.

Note that boolean assignment is not the only operator where 16.1.7 is
going to apply with another rule. Consider the non short-circuiting
and/or operators (& |) or boolean exclusive-or (^). In those cases
16.1.7 applies along with 16.1.10. But once again you have to apply
16.1.7 first.

16.1.7 bridges between the boolean expressions where you have to
consider when the expression is true and when the expression is false
and other expressions where you don't.

Basically 16.1.7 says that we only have to consider the when-true and
when-false information for a limited set of operators. When it is other
operators it must be definitely assigned either way.

You can still get to the same result without 16.1.7. 16.1.7 just makes
it a little smoother. We start with this from the if-statement rule 16.2.7:

ref is definitely assigned before the if block if it is definitely
assigned after retain = XXXX && YYYY when true.

16.1.8 gives us this

ref is definitely assigned after retain = XXXX && YYYY if it is
definitely assigned after XXXX && YYYY.

Rule 16.1.8 says nothing about "when true". You aren't allowed to carry
the when true part from 16.2.7 into evaluating the assignment. Rule
16.1.7 is there to make that explicitly clear by saying you drop the
when true unless it is one of a limited set of boolean operators (the
ones that have a control flow nature to them).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,721
Latest member
NelsonHeil

Latest Threads

Top