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.
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) { }
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.
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; }
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; } }
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.
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.
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.
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) { } }
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.
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.
Created attachment 42717 [details] Project
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.
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.
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.
*** Issue 112579 has been marked as a duplicate of this issue. ***
*** Issue 119527 has been marked as a duplicate of this issue. ***