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 103356 - reverse engineering to discover getter/setters
Summary: reverse engineering to discover getter/setters
Status: REOPENED
Alias: None
Product: uml
Classification: Unclassified
Component: Reverse Engineering (show other bugs)
Version: 5.x
Hardware: PC Windows XP
: P2 blocker with 1 vote (vote)
Assignee: issues@uml
URL:
Keywords:
: 112579 119527 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-05-05 00:36 UTC by thoalex
Modified: 2007-10-26 01:36 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Project (30.65 KB, application/octet-stream)
2007-05-24 02:08 UTC, thoalex
Details

Note You need to log in before you can comment on or make changes to this bug.
Description thoalex 2007-05-05 00:36:48 UTC
When generating setters/getters for a class, the UML code generator, generates 
methods that return 0 or null for the getters while the setters do nothing:

    public int getObitUpsellId() {
        return 0;
    }

    public void setObitUpsellId(int val) {
    }

    public String getAbbrev() {
        return null;
    }

    public void setAbbrev(String val) {
    }
Comment 1 Andrew Korostelev 2007-05-15 06:26:19 UTC
Getters have not void return type.
Therefore to get compilable code they should return at least default value.

Setters can do nothing. So we do not add logic to them.

We can add logic instead of user only if it is necessary to have compilable code.
Comment 2 thoalex 2007-05-15 06:35:24 UTC
If I generate a class MyNames in UML, and the class has a property called 
Abbrev that is a String.  Then when I click on "Generate Code" for that class:

A setter should be generated like the following:

public void setAbbrev(String val) {
    this.abbrev = val;
}

public String getAbbrev () {
    return this.abbrev;
}

Currently what it is doing is the following:

Generating a setter like so:

public void setAbbrev (String val) {
}

and a getter like so:

public String getAbbrev() {
    return null;
}
Comment 3 Peter Lam 2007-05-15 07:30:15 UTC
Looks like a regression to me. However, I just tried with NetBeans 5.5 UML and
could not reproduce this issue. I got the following codes generated correctly
for a class with 2 attributes of type int and String. Is there something that I
did incorrectly to reproduce your case?

public class C1 {
    private String abbrev;

    private int abbrev2;

    public C1() {
    }

    public String getAbbrev() {
        return abbrev;
    }

    public void setAbbrev(String val) {
        this.abbrev = val;
    }

    public int getAbbrev2() {
        return abbrev2;
    }

    public void setAbbrev2(int val) {
        this.abbrev2 = val;
    }
}
Comment 4 Sergey Petrov 2007-05-15 14:55:12 UTC
I can't reproduce with 070515 build for 6.0, and uml in 5.5.1 and jse8.1
But as I remember it was default behavior in jse8.
Comment 5 thoalex 2007-05-16 04:02:32 UTC
You all just put out a release to the UML core so it's possible that has fixed 
it.  I'll update in a couple of days.
Comment 6 Peter Lam 2007-05-16 07:14:19 UTC
Yes, there's a patch that was just pushed to the update center. However, I was
not able to reproduce with and without the patch though. Please do update this
issue after you try the latest update. Thanks.
Comment 7 thoalex 2007-05-23 03:13:30 UTC
Still does it.  This time I did a "Reverse Engineer" of code.  When I did 
that, it only created attributes for native types.  Then I did a "Generate 
Code" and I have the "0" and "null" thing:

package com.evasive.utilshds.users;

import com.evasive.utilshds.address.Address;
import com.evasive.utilshds.email.Email;


public class Users {
    private int usersId;

    private boolean active;

    private String name;

    private String password;

    private String firstname;

    private String lastname;

    private Address address;

    private Email email;

    public Users() {
    }

    public int getUsersId() {
        return 0;
    }

    public void setUsersId(int val) {
    }

    public boolean getActive() {
        return true;
    }

    public void setActive(boolean val) {
    }

    public String getName() {
        return null;
    }

    public void setName(String val) {
    }

    public String getPassword() {
        return null;
    }

    public void setPassword(String val) {
    }

    public String getFirstname() {
        return null;
    }

    public void setFirstname(String val) {
    }

    public String getLastname() {
        return null;
    }

    public void setLastname(String val) {
    }

    public Address getAddress() {
        return null;
    }

    public void setAddress(Address val) {
    }

    public Email getEmail() {
        return null;
    }

    public void setEmail(Email val) {
    }
}


Comment 8 Peter Lam 2007-05-23 22:40:03 UTC
Very strange. I just wonder what's happening. Is it possible that you can zip up
your uml project and attached to this issue so we can take a look to see if we
can reproduce the problem. thanks.
Comment 9 Peter Lam 2007-05-23 23:07:22 UTC
Oh, one other thing you can try is to start NetBeans in a new userdir to see if
the problem goes away. Sometimes there are corrupted files caused by other
things that are unkonwn.
Comment 10 thoalex 2007-05-24 02:08:37 UTC
Created attachment 42717 [details]
Project
Comment 11 thoalex 2007-05-24 02:11:13 UTC
Ok, I sent an attachment.  Look at com.evasive.utilshds.users.User.  When I 
reverse engineered it, it should have had an attribute of 
com.evasive.utilshds.address.Address.  Those attributes disappeared.  Then 
when I generate code, it creates the 0/null issue in 
com.evasive.utilshds.users.User.

UtilsHDS-Model1 is a new UML project that I created from the actual Project (I 
can send that as well if needed).  I've had this issue happen on 2 different 
computers (with different projects)  Recreating projects doesn't help.
Comment 12 Andrew Korostelev 2007-05-24 17:18:19 UTC
two comments:
1) User still has attribute of Address type.
But it is shown as 'Aggregation' link - just another view for the same relation.
You can see it in model tree or if you put both elements to diagram. 

2) you are right - expected methods bodies are generated for getter/setter just
created in uml. But they are generated incorrectly for Reverse Engineered methods.
It is a BUG.
Comment 13 Viktor Lapitski 2007-07-03 21:54:35 UTC
the [attribute, getter/setter] association would practically mean 
an automated keeping of getter/setter methods in sync with 
he attribute. That makes perfect sense for the case when 
source is originally derivated from the model.

For the opposite case - ie. when already existing source is REd - 
the getter/setter(s) is supposedly already have bodies which 
may be more complicated than vanila ones generated by default 
(though it is now a supported feature that one can edit/create 
new template to be used to generate code) In this case the 
code generation with merging back into existing source would 
by (current) default update only headers of method declarations, 
until it is a getter/setter for which (current) default is to 
update (that actually means overwrite with new generated one, 
and in no way it is a refactoring) both, method's header and body.     

Thus it is kind of half and half. I.e. automated identification 
of some method during RE as getter or setter (i.e. meaning that 
it will be automatically kept in sync with an attribute 
that it is associated with) may be a desired behaviour in as many 
cases as the number of cases where it may be an undesired one. 
Please let me know what think.   
Comment 14 Viktor Lapitski 2007-08-10 23:50:40 UTC
*** Issue 112579 has been marked as a duplicate of this issue. ***
Comment 15 Viktor Lapitski 2007-10-26 01:36:34 UTC
*** Issue 119527 has been marked as a duplicate of this issue. ***