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 80564 - Objects from java.lang package are not correctly imported into source file
Summary: Objects from java.lang package are not correctly imported into source file
Status: VERIFIED INVALID
Alias: None
Product: uml
Classification: Unclassified
Component: Synchronization (show other bugs)
Version: 5.x
Hardware: PC Windows XP
: P1 blocker (vote)
Assignee: issues@uml
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-19 12:49 UTC by bugbridge
Modified: 2006-10-10 15:49 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugbridge 2006-07-19 12:49:59 UTC
Original submitter: sunflower

Description:

Steps to reproduce:

- Create a class element and name it 'MyClass'
- Insert attribute 'private Object myAttribute' into class element.
  'Object' class element appears under 'Model' node in the UML project.
- Drag and drop 'Object' class element on diagram.
- Draw 'Generalization' link from 'MyClass' to 'Object' class element.
- Build the project.
  The project is not compiled because of 'Object' is not correctly imported:

pack\MyClass.java:3: '.' expected
import Object;
1 error
BUILD FAILED (total time: 0 seconds)

===================================================
package pack;

import Object;

public class MyClass extends Object {

    private Object myAttribute;
    public MyClass() {
    }

    public Object getMyAttribute() {
        return myAttribute;
    }

    public void setMyAttribute(Object val) {
        this.myAttribute = val;
    }
}
===================================================
Comment 1 Craig Conover 2006-08-14 19:57:56 UTC
Reivew: bug is as reported. This is common issue with all the well-known Java
object types. For some reason, they are added to the default package, and
sometimes even duplicated in the proper package (like java.lang) but not removed
from the default package. 

This will also happen when source code is modified and the import statement is
generated after the model has been updated.
Comment 2 Trey Spiva 2006-09-21 19:43:17 UTC
This is working as designed.  When you create the "Object" class in the root of
the tree, how are we suppose to read the users mind, to know that was suppose to
be "java.lang.Object".  We have to assume, that the user want to create a new
class in the default package.  So, that is what we do.  

As far as putting the import statement into the file.  If you create a Class
named "Foo" and put it into the default package.  Then you create a package
named "bar" and put a class named "Sue" into "bar".  Now make "sue" extend
"Foo".  You will get an error and the hint want to import "Foo".  The import
created by the hint, is the same as we will create, and it will not compile.
Comment 3 Trey Spiva 2006-09-21 19:44:50 UTC
In this case, you should put the "Object" class in a "java", "lang" package
structure.
Comment 4 Alexandr Scherbatiy 2006-09-22 10:21:42 UTC
The UML must not to generate uncompilable java code in any case.
Comment 5 Trey Spiva 2006-09-22 16:16:47 UTC
Garbage in, Garbage out.  If the user does not give us valid information, we can
not generate valid source code.  A class that is in a package, can not reference
a class in the default package.  That is now a compile error in java. 
Therefore, even if we did not put an import statement, we will get a compile error.

The java editor has the same problem.  Matter a fact we are using the same
import manager to generate the import statement.  So, if anything you should
create an issue against the editor team.
Comment 6 Alexandr Scherbatiy 2006-09-25 10:34:27 UTC
Please, carefully read the summary of the bug. The problem is not that
user creates his class under default package. The problem is that UML module
puts the java.lang.Object class under default package. It is a bug of course that
if anybody uses the 'Object' datatype which was generated by the UML module
then java code is not compiled.
You need to fix the problem. For example do not put the 'Object' datatype
under the default package or do not insert import into javcacode if Object is
from default package.

Comment 7 Trey Spiva 2006-09-25 14:38:47 UTC
Yes, but UML is not and should not be Java centric.  If we are Java centric will
will start to run into problem when we start to support languages like C++ and
VB.  Therefore, we can not assume that Object means java.lang.Object.  The
correct solution is to support libraries, which we have an RFE for already. 
Comment 8 Andrew Korostelev 2006-09-25 17:37:20 UTC
this issue actually consists of several issues:

issue 79526 - custom type datatype is generated in default package
enhancement issue 85705 - objects from java.lang package should be created as
datatypes in appropriate package
issue 85702 - imports generated in java src are different for diffrent object usages
Comment 9 Alexandr Scherbatiy 2006-10-10 15:49:49 UTC
The issue was divided into three issues.