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 51649

Summary: ClassCastException when moving a class
Product: java Reporter: Roman Strobl <rstrobl>
Component: UnsupportedAssignee: Tomas Hurka <thurka>
Status: CLOSED FIXED    
Severity: blocker Keywords: RELNOTE
Priority: P2    
Version: 4.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Exception
Project on which rename package fails
Project on which moving of a class fails by exception

Description Roman Strobl 2004-11-18 15:02:23 UTC
[Netbeans 4.0 rc1; JDS v.2; JDK 1.4.2_06]

ClassCastException occurs whenever I move a class
from one package to another. I do it by DnD in the
projects tab. Due to this exception the
refactoring dialog doesn't appear. Evaluate if
this should be fixed for 4.0 final release.
Comment 1 Roman Strobl 2004-11-18 15:02:53 UTC
Created attachment 18956 [details]
Exception
Comment 2 Jan Chalupa 2004-11-18 15:11:19 UTC
Reliably reproducible when starting with a clean userdir? Can you
provide an exact testcase?
Comment 3 Jan Chalupa 2004-11-18 15:16:03 UTC
I cannot reproduce it with a simple project (2 packages, 2 classes).
Comment 4 Roman Strobl 2004-11-18 15:27:42 UTC
100% reproducible with clean userdir on attached project. Just try to
move class A to another package by DnD in Projects view. Not
reproducible on a new simple project with 1 class and 2 packages, so
it's probably not as general as I thought.
Comment 5 Roman Strobl 2004-11-18 15:29:18 UTC
Created attachment 18958 [details]
Project on which rename package fails
Comment 6 Roman Strobl 2004-11-18 15:30:06 UTC
Created attachment 18959 [details]
Project on which moving of a class fails by exception
Comment 7 Marek Grummich 2004-11-18 15:55:22 UTC
I am able to reproduce it too! There is a difference between package
declaration (package test;) and file location in the package/folder
structure (<src>/abc/A.java)
Comment 8 Roman Strobl 2004-11-18 15:59:22 UTC
You're right, note that it also happens for classes B and C whose
package is ok. I see the project code got broken due to refactoring
tests :-(
Comment 9 Martin Matula 2004-11-18 16:19:05 UTC
This happens when there is a field in the code of the same name as a
package. In this particular case there is a package named test
containing class A and this class A has a field named test. Class D
extends A and references A by its fully qualified name in a body of a
method (test.A). The attribution code wrongly assumes that test is the
name of the variable rather than name of the package.
Comment 10 Tomas Hurka 2004-12-04 08:57:37 UTC
Fixed in trunk.
Checking in org/netbeans/modules/javacore/parser/MDRParser.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/parser/MDRParser.java,v  <--  
MDRParser.java
new revision: 1.63; previous revision: 1.62
done
Comment 11 Roman Strobl 2004-12-06 10:42:36 UTC
Ok, now there's no exception, good. For verification purposes I've
tried to undo this action - moving a class to another package when the
package is broken. This doesn't seem to work, try to follow the steps
in my comment from 2004-11-18 07:27 PST and after the class is moved,
try Refactor->Undo. The contents of the class are reverted but the
class stays in the new package. 

Feel free to close and file another issue if this problem is not
connected with the fix.
Comment 12 Martin Matula 2004-12-06 12:00:35 UTC
This is currently as designed. DnD is a separate operation from the
refactoring, which responds to the fact the files were moved. The Undo
action reverts only the changes made by refactoring itself.
This was agreed upon with the UI team for 4.0 and is a separate issue
covered by a separate report (see issue 48676 - clearly a duplicate of
this, and issue 50980, which is caused by the same thing).
Comment 13 Roman Strobl 2004-12-06 12:07:42 UTC
Ok, thanks for explaining... IMO this way it is very uncomfortable for
users, agree it is a seperate issue. Verified.
Comment 14 Jan Chalupa 2004-12-08 05:51:42 UTC
Waiver approved for 4.0.
Comment 15 Quality Engineering 2007-09-20 11:59:24 UTC
Reorganization of java component