Bug 475462 - [clean up][save actions] "Add final modifier to private fields" causes compilation problem by erroneously adding final keyword to non-final private field
Summary: [clean up][save actions] "Add final modifier to private fields" causes compil...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-20 05:40 EDT by Arnaud Installe CLA
Modified: 2023-05-15 11:31 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 Arnaud Installe CLA 2015-08-20 05:40:26 EDT
In the code snippet below, I have an enum defined inside a class.
For serialization purposes, I have 2 constructors: one that initializes the enum's member variable, and one that doesn't.

With the save action "Add final modifier to private fields" enabled, eclipse refuses to save the member variable without the 'final' modifier, which, due to the second constructor, causes compilation to fail.

I believe this used to work correctly for ancient versions of eclipse.

Workarounds:
1/ either disable the save action when saving that file, and re-enable afterwards.
2/ edit the file with a different editor to remove the 'final' keyword.

==========
final class Test {
    enum Code {
        FOO("Foo.");

        private final String message;

        Code(final String message) {
            this.message = message;
        }

        /**
         * For serialization purposes.
         */
        Code() {
            // NOP
        }

        public String getMessage() {
            return message;
        }
    }
}
==========
Comment 1 Dani Megert CLA 2015-08-20 08:07:51 EDT
Test Case:

final class Test {
    enum Code {
        FOO("Foo.");

        private String message;

        Code(final String message) {
            this.message = message;
        }

        Code() {
        }
    }
}
Comment 2 Eclipse Genie CLA 2021-04-27 18:24:52 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 3 Eclipse Genie CLA 2023-05-15 11:31:04 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.