Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 272532 - [clean up] "Use modifier 'final' where possible" can introduce compile errors
Summary: [clean up] "Use modifier 'final' where possible" can introduce compile errors
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-16 13:26 EDT by Chris West (Faux) CLA
Modified: 2009-11-05 12:51 EST (History)
4 users (show)

See Also:
markus.kell.r: review+


Attachments
Testcase and simplest possible fix (4.08 KB, patch)
2009-10-22 18:05 EDT, Chris West (Faux) CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris West (Faux) CLA 2009-04-16 13:26:16 EDT
Build ID: I20090313-0100

Steps To Reproduce:
1. Create a class with a private field and a constructor that can return before assigning to said field.  e.g.

class Choo
{
  private int a;
  Choo(int b)
  {
    if (1 == b)
      return;
    a = 2;
  }
}

2. Source -> Cleanup.. 
3. Ensure Code Style -> Variable declarations -> Use modifier 'final' where possible -> Private fields is ticked.
4. Run the clean-up.

'final' will be added to the private field (a), which will cause the constructor to error: "The blank final field a may not have been initialized"

Can work around this by putting in the implicit "=0;" on the private field.

--
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB
Command-line arguments:  -os win32 -ws win32 -arch x86_64
Comment 1 Olivier Thomann CLA 2009-04-16 13:29:28 EDT
Move to JDT/UI
Comment 2 Chris West (Faux) CLA 2009-10-22 18:05:18 EDT
Created attachment 150316 [details]
Testcase and simplest possible fix

Simplest possible fix; if any constructor that returns at any point assigns to the private field, it can't be made final.
Comment 3 Markus Keller CLA 2009-11-05 12:51:17 EST
Thanks, released to HEAD.

To be honest, that whole clean up should be rewritten to just
- create a working copy with all supported variables set to final
- compile the working copy
- create changes for those variables which didn't introduce a definite assignment problem