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 235330 - Unexpected 'duplicate class' error after changing class' name in the source
Summary: Unexpected 'duplicate class' error after changing class' name in the source
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-30 17:58 UTC by ionuion
Modified: 2016-03-23 18:49 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter: DEFECT


Attachments
mano (642.98 KB, patch)
2016-03-23 18:48 UTC, kestutis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ionuion 2013-08-30 17:58:47 UTC
Environment:
Product Version: NetBeans IDE Dev (Build 201308300001)
Java: 1.7.0_40; Java HotSpot(TM) 64-Bit Server VM 24.0-b55
Runtime: Java(TM) SE Runtime Environment 1.7.0_40-b40
System: Mac OS X version 10.7.5 running on x86_64; UTF-8; en_US (nb)
User directory: /Users/ionuion/Library/Application Support/NetBeans/dev
Cache directory: /Users/ionuion/Library/Caches/NetBeans/dev

1. Create new project form samples (Java > Anagram Game)
2. Open class StaticWordLibrary
3.replace line 37 with
'final class StaticWordLibrarySuffix extends WordLibrary {'

4. replace line 32 with
'package com.toy.anagrams.newpackage;'

5. click the suggestion bulb on line 32. Select 'Move class to correct folder'
6. hover over the line 37.

Expected result:
- 'class StaticWordLibrarySuffix is public, should be declared in a file named StaticWordLibrarySuffix.java' displayed
- option in the suggestion box 'Rename file to StaticWordLibrarySuffix.java' offered

Actual result:
- 'duplicate class: com.toy.anagrams.newpackage.StaticWordLibrarySuffix' message displayed'
- No option to rename the file to the new class name
Comment 1 Svata Dedic 2013-09-13 13:04:13 UTC
In fact, after step 3, NB 7.4 will start to complain about duplicate class StaticWordLibrarySuffix - the file must be saved though. In the original scenario, the file was auto-saved at the start of refactoring.

The StaticWordLibrarySuffix ClassSymbol was entered based on the .sig file listed by ProxyFileManager; taken from .sig file. StaticWordLibrary ClassSymbol is entered into the package based on the .java filename.

Then Enter phase begins, classEnter/visitClassDef is called on the CompilationUnitTree subtrees. On the StaticWordLibrarySuffix, the ClassSymbol (coming from the .sig) file is found and reused.

During Attrib phase, the constructor refrerence provokes findGlobalType, which completes the ClassType for "StaticWordLibrary" (originally created based on .java file existence), and the StaticWordLibrary.java file is processed again.

Then the 'duplicate' error is issued as visitClassDef encounters the same class definition from the source twice.

Since after entering the entire CU of the source file, all classes from that file should have been entered and completed, if it would be great if, before attribution phase, the ClassSymbol with the same name as the source file, if it exists and is not complete, was replaced with a complete error (not exists) symbol.
Or some other way :)
Comment 2 abreneliere 2014-02-25 23:55:34 UTC
I had the error Duplicate Class 'toto' for a class located in the package
'titi.tata'.

In the header of the file the line was missing:
package toto.titi;

Adding  "package toto.titi;" solved the problem. I post it because the error message could have been more explicit.
Comment 3 kestutis 2016-03-23 18:48:49 UTC
Created attachment 158982 [details]
mano