Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 357649

Summary: [convert local] 'Convert Local Variable to Field' creates compile error when expression throws checked exception and target is 'Field declaration'
Product: [Eclipse Project] JDT Reporter: James Shaw <js102>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: minor    
Priority: P4 CC: markus.kell.r
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description James Shaw CLA 2011-09-14 11:30:20 EDT
Build Identifier: 

This would be useful to avoid the compile error you get after performing this refactor.

Reproducible: Always
Comment 1 Markus Keller CLA 2011-09-14 13:38:37 EDT
Example (convert "var" to field, initialize in field declaration):

package xy;
public class Try {
    void foo() throws ClassNotFoundException {
        String var= Class.forName("ABC").getName();
        System.out.println(var);
    }
}

As the error on the field tells, a solution is to add the thrown exception to all constructors, e.g. add this:

    public Try() throws ClassNotFoundException {
    }

So we should not block this option, since that's maybe exactly what the user wants.

We could add a warning about this problem to the refactoring, but I wouldn't silently add the throws clauses or the constructor.

But a Quick Fix that adds the throws clauses or the constructor would be nice.
Comment 2 James Shaw CLA 2011-09-14 15:43:55 EDT
Thanks for clarifying.  I didn't think about being able to throw the exception from the constructors.  Could the Quick Fix also happen when you convert the local variable to a field?  I'm not sure if that would desirable or not, tbh.
Comment 3 Eclipse Genie CLA 2020-05-27 12:02:36 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2022-05-20 14:04:32 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.