Bug 357649 - [convert local] 'Convert Local Variable to Field' creates compile error when expression throws checked exception and target is 'Field declaration'
Summary: [convert local] 'Convert Local Variable to Field' creates compile error when ...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P4 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-14 11:30 EDT by James Shaw CLA
Modified: 2024-05-10 15:40 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.
Comment 5 Eclipse Genie CLA 2024-05-10 15:40:39 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.