netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Swing designer automatically removes enum references in components

Open mflydahl opened this issue 1 year ago • 2 comments

Apache NetBeans version

Apache NetBeans 20

What happened

When opening a project in the designer with generated code from an old NetBeans-version, the designer will automatically change path to enums with the actual plain text value from the enum. This means that future updates in the enum will not be likewise updated in the swing component.

I've seen this behavior in setText() and setToolTipText(). See reproduction details.

Language / Project Type / NetBeans Component

No response

How to reproduce

  1. Open class, which contains the following generated code (or equivalent): avtaleKnapp.setText(ProgramEnum.AVTALEVEDL.getDescription()); avtaleKnapp.setToolTipText(ProgramEnum.AVTALEVEDL.getTooltip());

  2. Save the class again, and the enum reference has been replaced with the string value from the enum: avtaleKnapp.setText("Agreement"); avtaleKnapp.setToolTipText("Agreement");

Did this work correctly in an earlier version?

Apache NetBeans 16 or earlier

Operating System

Ubuntu 20.04

JDK

11

Apache NetBeans packaging

Apache NetBeans Snap Package

Anything else

Probably everytime, but I have not been able to try more than once. This happened when opening an old project in the designer to remove deprecations. Didn't notice that the enum references had been replaced with the plain text value until I created a pull request.

Are you willing to submit a pull request?

No

mflydahl avatar Jan 24 '24 10:01 mflydahl

looks like the compiler is inlining the String as constant

mbien avatar May 23 '24 06:05 mbien

I wasn't able to reproduce this. The custom code for the enum method call remained in the file for me.

mbien avatar Oct 11 '24 08:10 mbien