This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 121086 - Cannot correctly rename enum variable
Summary: Cannot correctly rename enum variable
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 6.x
Hardware: All All
: P4 blocker with 1 vote (vote)
Assignee: issues@java
URL:
Keywords:
: 121221 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-11-04 08:34 UTC by jozart
Modified: 2009-11-02 11:16 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Demo failure in renaming 'enum' variable name (322 bytes, text/plain)
2007-11-04 08:35 UTC, jozart
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jozart 2007-11-04 08:34:01 UTC
Refactor-Rename fails to rename variables named 'enum'.

Renaming 'enum' to 'iter' in this line of code:

    Enumeration enum = new Vector().elements();

Produces this:

    Enumeration iternew Vector().elements();

(Source code attached.)
Comment 1 jozart 2007-11-04 08:35:35 UTC
Created attachment 52466 [details]
Demo failure in renaming 'enum' variable name
Comment 2 jozart 2007-11-04 08:37:56 UTC
Reproduced in 6.0 Beta 2.

May be related to Issue 72263 (Cannot rename enum field).
Comment 3 Jan Pokorsky 2007-11-04 16:38:06 UTC
In jdk 1.5 and later 'enum' is a keyword. Your source is broken and the refactoring should not proceed. It is a P4
defect. In order to refactor this case you have to use source level 1.4 or java platform 1.4 in your project properties.
Note that compiler annotations warn you about this.
Comment 4 jozart 2007-11-04 17:46:36 UTC
Please reevaluate priority.

There's still tons of code written for older versions of Java that needs to be rebuilt (and possibly ported) to Java 5
or later.  NetBeans should make this process easier, not break the code even more.

The renaming support is clearly broken in this case. Try the demo provided and you'll see errors in the log file. 
There's also no way to undo, AFAICT.

The renaming support needs to either balk at attempting to rename a variable in broken code, or do it correctly.
Comment 5 Jan Pokorsky 2007-11-05 13:02:39 UTC
[NetBeans IDE Dev (Build 071102)]

It is probably a misunderstanding. Of course we still support older code but you have to use proper configuration then.
As I wrote there is an incompatibility between JDK 1.4 and 1.5 as the new keyword enum was introduced. So to refactor
such a code either use java platform 1.4 or use source level 1.4 in case you use java platform 1.5 or higher for your
project. The red underwave warns you about that. Move the mouse over the underwaved code to see detailed warning.

What errors in log are you talking about? I see no attachment here and if I try to reproduce no error is logged too.

Undo seems to be really broken in this case.

I agree again the refactoring should balk but it is P4 issue.
Comment 6 jozart 2007-11-05 19:39:18 UTC
I'm afraid the existing behavior may result in a bad experience for first-time NetBeans users trying to build old code.

Another likely scenario is: Naive user types in some Java code using 'enum' as a variable name and then tries to fix it
using the rename action.

The reviewer's explanation of the source setting is interesting, but it's not something a new user will be aware of.
They are much more likely to be aware of refactoring and expect it to just work.

When I open the attached code in the editor, I see a red exclamation point with this note:

  as of release 5, 'enum' is a keyword and may not be used as an identifier
  (use -source 1.4 or lower to use 'enum' as an identifier.)

This is only partially helpful:

1. The "-source 1.4" language is not meaningful to new users. To target them, the note should refer to project settings
not command-line options.

2. It doesn't tell me that I have to change the source setting before I can use the rename action to rename 'enum' (and
neither does the rename action).
Comment 7 Jan Lahoda 2007-11-15 12:01:26 UTC
*** Issue 121221 has been marked as a duplicate of this issue. ***
Comment 8 David Strupl 2009-03-31 15:55:21 UTC
Resolving all issues with milestone "future" as LATER. If you feel strongly that
it should be implemented please reopen and set the target milestone to "next".
Comment 9 Quality Engineering 2009-11-02 11:16:14 UTC
NetBeans.org Migration: changing resolution from LATER to WONTFIX