Mark,

On 4/22/14, 4:30 PM, Mark Thomas wrote:
> On 22/04/2014 21:21, Christopher Schultz wrote:
> 
>> Before posting, I checked just so I wouldn't embarrass myself. It
>> worked just fine. My guess is that you changed the implementation
>> to throw an exception after removing the 'final' which then makes
>> the 'final' legal again.
> 
> I don't see any variation that includes final that compiles.
> 
> Option 1:
> 
>     int final fipsModeState;
>     try {
>         fipsModeState = SSL.fipsModeGet();
>     } catch (Exception e) {
>         throw new IllegalStateException(e);
>     }
> 
> 
> This failure looks correct to me since it should be illegal to change
> the value of a final variable after it has been declared.
> 
> 
> Option 2:
>     try {
>         int final fipsModeState = SSL.fipsModeGet();
>     } catch (Exception e) {
>         throw new IllegalStateException(e);
>     }
> 
> This code snippet it OK but compilation fails as the scope of
> fipsModeState is now limited to the try block and it is needed outside
> of that so again, compilation fails.
> 
> 
> How do you propose to mark fipsModeState as final and still have the
> code compile?

$ cat FinalTest.java
public class FinalTest {
  public static void main(String[] args) {
    final int fipsModeState;

    try {
      fipsModeState = 1;
    } catch (Exception e) {
      // Do nothing
    }
  }
}
$ javac -J-showversion FinalTest.java
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
[no warnings. no errors]

Honestly, I was surprised to see that the compiler allows a code path
where fipsModeState was not set. It seems that the compiler allows you
to get by until you try to actually use the value, at which point you'll
get an "uninitialized local" error.

-chris

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to