netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

The GUI Builder produces code for boxed primitive properties that is deprecated for removal

Open juersimon opened this issue 1 year ago • 0 comments

Apache NetBeans version

Apache NetBeans 20

What happened

When a JComponent has a property of type Long (not long) and a value is entered using the properties editor, the GUI Designer creates: component.setProperty(new java.lang.Long(123L)); Since the Long(long) constructor is deprecated for removal and manual boxing is not required, the following code should be generated instead: component.setProperty(123L); This happens for all boxed primitive values except Boolean. Furthermore, it is not possible to set a value to null using the Properties Editor. This also applies to Boolean.

Language / Project Type / NetBeans Component

Java

How to reproduce

  1. Create a JComponent that contains a property of type Long, Integer, etc.
public class TextField extends JTextField {
    
    private Long val1 = 123L;

    public Long getVal1() {
        return val1;
    }

    public void setVal1(Long val1) {
        this.val1 = val1;
    }
}
  1. Create a new container (JPanel, JDialog etc.) using the GUI Designer and add this component to the container.
  2. Change the value of val1 using the property editor and view the generated code.
  3. Try setting the value of val1 to null using the property editor.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows / Linux

JDK

all since JDK 9

Apache NetBeans packaging

Apache NetBeans provided installer, Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

juersimon avatar Feb 09 '24 15:02 juersimon